Please let me know if this post doesn't belong here... I couldn't find a dedicated forum for network programming, so posted this here.
I'm developing a client and server for using Winsock/TCP/C++. I'm relatively new to network programming and have a few doubts :
- Suppose I send 8 bytes from the server in a single send( ), can I be sure that I will ALWAYS get 8 bytes in a single recv at client(assuming that I specify 8 bytes as my buffer size in recv)? The question is, is it possible (probably due to network conditions) that the client recv's 3 (or somethin else <8) bytes only first; and the rest of the 5 bytes at the next recv? In that case I'll have to do recv in loop until I get 8 bytes.
- As server resources are at a premium, I don't want to keep a connection idle for too long. I'm facing a dilemma on how to do this:
When I detect a timeout I can simply close the socket, thereby releasing system resources. But if I do this, the client would have no clue that it was timed out.
I also want to client to know that it has been timed out, for which I'll need to send a timeout message to the client and wait to make sure it has received it. But in this case, the socket will still be open, nullifying the whole purpose of timing out a client. Is there a way to timeout that meets both these criteria?
Thanks for the help!