Saturday 15 January 2011

c - How to handle when a Client or Server is Down in a UDP Application -


I am developing Windows applications for client server communication using UDP, but since UDP is no connection, Whenever a client goes down the server does not know that the customer is closed and keeps sending data. The same is the case when the server is down how can I fulfill the condition that whenever a customer or server stops, the other party should know it and handle it. Waiting for reply.

Whatever you are asking is beyond the scope of the UDP. To obtain this, you have to apply your own protocol above the UDP.

A simple idea can be sent from time to time (on the other hand TCP is in this facility)

You have a simple implementation as follows:

  • Continue sending those messages to a background thread and waiting for the replies.
  • On receiving the answers, you can populate some types of data structure or file containing the list of live devices.
  • Your other main threads (or threads) may contain the following changes:

    1. Before sending any data, check that the customer you send Want to present it in that file / data structure.
    2. If not, skip this client.
    3. Repeat populated files / data structure for all remaining customers.

      Ul>

    4. i1 = Use the following analogy instead of your background thread that sends a keepalive message.
    5. i2 = Your main thread (or threads) that send / receive data and do your other work.
    6. The RAW threat first tries to read i2 data structure / file that is i1 first I1 is updated by
    7. This means (worst position), i2 update list will not be found, and it can miss some clients this way.
    8. If this loss will be significant, I can suggest that you probably have a mechanism by which i1 is indicated by i2 whenever anyone Will finish the current writing
    9. If this loss is not important, then you can leave the above mechanism to accelerate your program.

      Explanation for Keepalive Message:

      You just need to send a very light message (usually there is no data. Only header information). Make sure this message is unique . You not want to define any other message as a text message.

      You can send this message to sendto () call. After the sending ends, recv () . Use

      to wait for the answer for a certain timeout. Log in every answer in the data structure / file, after the expiration of the expiration, for some time the gold goes to sleep. When that time expires, repeat the above procedure.

      To help you write a good, strong networking code, it is absolutely amazing that it tells many concepts.

No comments:

Post a Comment