title: Making recvfrom() function non-blocking
body: <p>I am working on a UDP server/client application. </p>
  
  <p>For finding out if any of the client is down, the 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 <code>recvfrom()</code> unless the client replies back, but if the client is down, the server blocks infinitely in call to <code>recvfrom()</code>.</p>
  
  <p>I want to implement such a functionality on my server so that it waits in the call to <code>recvfrom()</code> for a specific time (say 2 secs). If no data was received from the client within 2 seconds, the client is considered to be dead and <code>recvfrom()</code> returns.</p>
  
  <p>Is there any way to do it? I searched internet but found solutions like setting <code>MSG_DONTWAIT</code> flag that returns immediately when no data received, but in my case, I don't want <code>recvfrom()</code> to return immediately but wait for data for a specific duration of time, and when no data received for that specific duration, the <code>recvfrom()</code> function should return. </p>