Does BeginReceive() get everything sent by BeginSend()?

Posted by IVlad on Stack Overflow See other posts from Stack Overflow or by IVlad
Published on 2010-05-06T09:09:47Z Indexed on 2010/05/06 9:18 UTC
Read the original article Hit count: 154

Filed under:
|
|
|

I'm writing a program that will have both a server side and a client side, and the client side will connect to a server hosted by the same program (but by another instance of it, and usually on another machine). So basically, I have control over both aspects of the protocol.

I am using BeginReceive() and BeginSend() on both sides to send and receive data. My question is if these two statements are true:

  1. Using a call to BeginReceive() will give me the entire data that was sent by a single call to BeginSend() on the other end when the callback function is called.

  2. Using a call to BeginSend() will send the entire data I pass it to the other end, and it will all be received by a single call to BeginReceive() on the other end.

The two are basically the same in fact.

If the answer is no, which I'm guessing is the case based on what I've read about sockets, what is the best way to handle commands? I'm writing a game that will have commands such as PUT X Y. I was thinking of appending a special character (# for example) to the end of each command, and each time I receive data, I append it to a buffer, then parse it only after I encounter a #.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET