C# – “End of Message” String for Sockets

csockets

What's a good end of message marker for a socket message schema in order to separate messages as they are received?

I had been using <EOF> but that seems a byte or too long and could POSSIBLY be sent in a message, especially if XML data was being sent.

Thanks!

Best Answer

One method is to approach this similar to AMF3: Before each message, send a 4-byte length indicating the number of bytes of data which will be sent as the message. In this way, even a 0-byte "empty message" can be sent, and no escape mechanism is needed.