Click here to Skip to main content
12,398,000 members (43,732 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C Windows Win32 udp
I am developing a windows application for Client Server communication using UDP, but since UDP is connectionless, whenever a Client goes down, the Server does not know that Client is off and keeps sending the data. Similar is the case when a Server is down. How can I cater this condition that whenever any of the Client or Server is down, the other party must know it and can handle it. Waiting for reply.
Posted 27-Mar-13 1:02am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

I did this many years ago in VB6 but as I recall an exception was thrown if they could not contact the machine name. However, if the machine is online but your app is not listening then what I did was implement a polling situation so if I did not get a response back in a certain amount of time it was assumed offline. Your other option is to use TCP.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

This depends on the used communication.

When the other side sends packets in regular intervals, you can stop sending packets when no data are received for a specific time and resume sending upon the next receive. If no data are send in regular intervals, just send them. Such packets are called keep-alive packets. If necessary, send a packet at program start to indicate that the client / server is present and trigger the other side to start sending.

Using the above, you will have packets send until the time out occurs. But this is normally not a problem. If your communication protocol can be changed, you might send additional special packets indicating that a server or client is going down so that the other side can stop immediately.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

You can set up your own handshake protocol on top of UDP. In other words, have the receiving machine send a response that the sender will process.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

A simple implementation is as follows:

Have a background thread keep sending those messages and waiting for replies.
Upon receiving replies, you can populate some sort of data structure or a file with a list of alive devices.
Your other main thread (or threads) can have the following changes:

Before sending any data, check if the client you're going to send to is present in that file/data structure.
If not, skip this client.
Repeat the above for all remaining clients in the populated file/data structure.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 28 Mar 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100