In my head it looks like this:

  1. I check the function ioctlsocket ((* this) .sock, FIONREAD, & arg); data availability to read recv;
  2. If there is nothing, I wait for example 100 ms and check again.
  3. If so 5-10 times there is nothing - then the server did not answer. Otherwise, I start reading the data.

I ask, because if the client calls recv immediately after send quickly, and the server does not have time to process and send a message back, does the client have nothing to accept? Or again I did not understand something? :)

Supplemented.

Customer:

  • 1 second - client sent data
  • 2 seconds, the client checked the buffer using ioctlsocket, no data

Server:

  • 1 second - server received data
  • 2 second - server processes data
  • 3 seconds - server sends data

Why I ask, can it be or not?

  • Explain the task. The server can not do something, there is a different buffer. - Nicolas Chabanovsky

1 answer 1

Use the select . It is possible to transfer the waiting time to the data. If data appears in the socket, it will return control. Otherwise, after a specified time has elapsed, a time-out error will return.

  • Is there a feature in windows? - Jakeroid
  • Found already on msdn. Thank. - Jakeroid