-
Send/Receive
I would like to hear some opinions on how you should make sure your Client-Server commnunication will work properly.
More in details, I am making a turned-based game. So what happens is that when you make a move an array of strings is updated with the specific string command. Then when your turn ends, I send all the strings through a network stream on a TCP/IP connection.
I want to use (for now) a synchronized/blocking Send()/Receive() method. Using .NET library. My question is, what measures do I have to take?
The data I am sending is small. Meaning that it should fit in one package. Do I have to make a confirmation method, like sending back an "Received" message? Or is this done anyway by the TCP/IP protocol for each package?
Will using one Send() method be better (one for the array of strings) or using one Send() for each string in the array? I would guess same thing...
-
If you are using TCP (which you should be), then the acknowledgements and packet level details will happen behind the scenes. All you need to do is call Send and Receive for the data you care about.
Keep in mind that if you send 1000 bytes on one side, and you attempt to receive 1000 bytes on the other side, there is no guarantee that you will receive all 1000 bytes. It make take 2 or more calls to Receive() to receive all the data. Also, if you call Send twice sending 1000 bytes each time, the receive side may get 2000 bytes with the first call to Receive().