I have question.
I create socket , connect , send bytes , all is ok.
and for receiving data i use recv function.
char * TOReceive= new char[200];
recv(ConnectSocket, TOReceive , 200, 0);
when there are some data it reads and retuns, succefull , and when no data waits for data, all i need to limit waiting time, for example if 10 seconds no data it should return.
Many Thanks.
Windows sockets has the
selectfunction. You pass it the socket handle and a socket to check for readability, and a timeout, and it returns telling whether the socket became readable or whether the timeout was reached.See: http://msdn.microsoft.com/en-us/library/ms740141(VS.85).aspx
Here’s how to do it:
If it returns true, your next call to
recvshould return immediately with some data.You could make this more robust by checking
selectfor error return values and throwing exceptions in those cases. Here I just returntrueif it says one handle is ready to read, but that means I returnfalseunder all other circumstances, including the socket being already closed.