Idetect the recv() timeout using the function select(). I put the receiving socket into the read set of the select() and pass the time out to the select() function. Then I check the return value of the select() function. in case there is data to receive, the return value would be 1. If the timeout value has passed, the retuned value is 0.