We have done some basic TCP communication, but have a few questions. We are communicating with a TCP server where the transaction flow is described as follows:
The sender initiates the transaction by sending an STX (ASCII 0x02) character, then waits for the recipient to reply by sending an ACK (ASCII 0x06) character. After an ACK is received, the sender transmits a four-byte, unsigned, big-endian integer representing the size of the message payload, followed by the payload, and finally a 16-byte MD5 message digest for the payload. If the recipient is satisfied with the message, it sends an ACK character.
<STX> = ASCII 0x02
<ACK> = ASCII 0x06
Sender: <STX> <0x00><0x00><0x00><0x05><'H'><'E'><'L'><'L'><'O'><0xEB><0x61>...
Recipient: <ACK> <ACK>
Using .Net sockets (System.Net.Sockets.Socket), what is the proper way to manage the STX/ACK transfer control? Does the socket handle this automatically (i.e. Do we simply call socket.Send(byteData)), or do we need to explicitly send the STX, wait for ACK, etc.?
The same goes for receiving: Do we simply receive the incoming data, or do we need to listen for an STX character, send an ACK, prepare for the payload, etc.?
If the transfer control is handled automatically, are there any specific socket flags that we need to set?
FYI: We found several links (like the following) that have proved useful for message framing, but none discuss the STX/ACK transfer control: