开发者

"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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜