"End of Message" String for Sockets
What's a good end of message marker for a socket message schema in order to separate messages as they开发者_如何学Python 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!
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.
If you're restricting the message data to printable characters, there are several control characters to choose from (ETX, EOT, Ctrl-Z, FS, EM, etc.) that historically have been used to signal end of message.
精彩评论