Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C Windows programming udp , +
I am working on udp server/client application. For finding out if any of the client is down, server sends a handshake message to the client. Then, the server waits for the response of client to send some data to assure that the client is active. For this the server blocks in call to recv_from() unless the client replies back, but if the client is down, the server blocks infinitely in call to recv_from. I want to implement such a functionality on my server so that it waits in call to recv_from for a specific time (say 2 secs). If no data received from the client within 2 seconds, the client is considered to be dead and recv_from returns. Is there any way to do it? I searched internet but found solutions like setting MSG_DONTWAIT flag that returns immediately when no data received, but in my case, I don't want recv_from to return immediately but wait for data for a specific duration of time, and when no data received for that specific duration, the recv_from function should retun. Any help is appreciated.
Posted 10-Apr-13 19:52pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This is the wrong way to do it, you should use a non-blocking socket (see http://msdn.microsoft.com/en-us/library/windows/desktop/ms740121(v=vs.85).aspx[^]). Keep a state table for each client and whenever a message is received mark the time in the table. Check your state tables periodically and if no message has been received in less than the timeout time, mark the client as not responding.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 255
2 Maciej Los 250
3 Shweta N Mishra 216
4 PIEBALDconsult 174
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,665


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 11 Apr 2013
Copyright © CodeProject, 1999-2014
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