TCP消息端最佳实践

发布于 2025-01-08 12:08:23 字数 189 浏览 1 评论 0原文

结束 TCP 消息的最佳实践是什么?我现在有了自己的自定义字符串,但我偏执地认为,如果运气不好,可能会在线路上传输包含最终消息 charcater(s)/string 的内容。

SMTP 服务器接受回车键,但是如果文本中“输入”了一段文本并通过网络传输,这不会让人感到惊慌吗?

我想得到一些关于这方面的想法。

谢谢

whats the best practice to end a tcp message? I now have my own custom string of characters, but I am paranoid that in a case of blind luck, its possible to transmit something on the wire that can contain your end message chracater(s)/string .

SMTP servers take the enter key, but won't that freak out if a peace of text has "enters" in it and is transmitted on the wire?

I would like to get some ideas on this.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

久隐师 2025-01-15 12:08:23

如果您使用自定义字符串作为结束指示符,则必须使用一些字符串转义技术确保该结束指示符不会出现在消息正文中。

例如,如果使用“\r\n”作为结束指示符,则必须将消息正文中的“\r\n”转换为其他形式。

If you are using a custom string as the end indicator, you must ensure that this end indicator won't appear in the message body, using some string escape techniques.

For example, if you are using "\r\n" as the end indicator, you must turn the "\r\n" in the message body to another form.

悲念泪 2025-01-15 12:08:23

可以更好地利用消息的长度并将其传递给开头吗?

有关文本协议的示例,请参见 此处。你的问题解决了一部分

An encoded string is a string with the following encoding rules.
- Characters in the range [0x10 - 0xff] are encoded as itselves.
- A character in the range [0x00 - 0x0f] is prefixed by 0x01 and
  shifted by 0x40. For example, 0x03 is encoded as 0x01 0x43.

Can better use the length of message and pass it the beginning?

For example of text protocol seee here. Your problem solve it part

An encoded string is a string with the following encoding rules.
- Characters in the range [0x10 - 0xff] are encoded as itselves.
- A character in the range [0x00 - 0x0f] is prefixed by 0x01 and
  shifted by 0x40. For example, 0x03 is encoded as 0x01 0x43.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文