“消息结尾";插座的字符串 [英] "End of Message" String for Sockets

查看:53
本文介绍了“消息结尾";插座的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

套接字消息架构的消息标记的一个好终点是什么,以便在接收到消息时将它们分开?

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

我一直在使用< EOF> ,但这似乎是一个字节或太长,可能会在消息中发送,特别是在发送XML数据的情况下.

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.

谢谢!

推荐答案

一种类似于AMF3的方法:在每条消息之前,发送一个4字节的长度,指示将作为字节发送的数据的字节数.信息.这样,即使是0字节的空消息"也可以发送,并且不需要转义机制.

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.

这篇关于“消息结尾";插座的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆