简体   繁体   English

Websockets消息完整性

[英]Websockets message integrity

When using a WebSocket full-duplex data connection between a client and a server, am I guaranteed, when sending two messages from the server, that I will receive those two exact same messages on the client, something TCP does not ? 当在客户端和服务器之间使用WebSocket全双工数据连接时,我保证,当从服务器发送两条消息时,我将在客户端上收到这两条完全相同的消息,而TCP则没有

In other words, if the server sends in turn hello and then its me , does the client always receive two messages containing hello and its me or is it possible the client receives helloit and then s me or even one only message like helloits me ? 换句话说,如果服务器依次发送hello然后发送给its me ,客户端是否总是收到两条包含hello its me消息,或者客户端是否可能接收到helloit然后s me或者甚至只有一条消息如helloits me

WebSocket originally had text message start and finish bytes, but that's old information. WebSocket最初有文本消息开始和结束字节,但那是旧信息。 There's a length component in the (Dec 2011) framing. (2011年12月)框架中有一个长度组件。 And btw, there a flag in the framing spec that specifies whether the frame is the whole "message" or a "message fragment", ie, there are other frames that make up this "message". 顺便说一句,在框架规范中有一个标志,指定框架是整个“消息”还是“消息片段”,即,还有其他框架组成这个“消息”。 Its up to the receiver to combine the fragments correctly to pass up to the application code. 它由接收器正确组合片段以传递给应用程序代码。 Normally you don't have to think about this unless you have very large "messages" (think of WS "messages" as "data" rather than true messages... WS is not really a "messaging" protocol per se). 通常你不必考虑这个,除非你有非常大的“消息”(把WS“消息”看成是“数据”而不是真正的消息...... WS本身并不是一个“消息”协议)。

But note, WebSocket is a low-level transport. 但请注意,WebSocket是一种低级传输。 Think of it like a web-based TCP. 可以把它想象成一个基于Web的TCP。 Application programmers should use high-level protocols "over WS/WSS" and not worry about ordering, reconnection, presence, pub/sub, tuple-spaces, guaranteed delivery, etc, etc. If we don't do this, dozens and dozens of decades-old application protocols will be re-invented. 应用程序员应该使用“通过WS / WSS”的高级协议,而不用担心订购,重新连接,存在,发布/订阅,元组空间,保证交付等等。如果我们不这样做,几十个和几十个几十年前的应用程序协议将被重新发明。

Having a very bad connection you may lose a message (however it should be resend with tcp), but it's very unlikely to be splitted in such a way. 有一个非常糟糕的连接你可能会丢失一条消息(但它应该用tcp重新发送),但它不太可能以这种方式分割。 Each text message has boundaries - start (0x00) and finish (0xFF) bytes. 每条文本消息都有边界 - 开始(0x00)和结束(0xFF)字节。 Browser should not mess messages. 浏览器不应该混乱消息。 Likely you can get messages in another order. 可能你可以用另一个订单获得消息。

How can you be more sure: 你怎么能更加确定:

  1. Add your own control sums to messages (but indeed it's overhead). 将您自己的控制总和添加到消息中(但实际上它是开销)。
  2. Use wss (websockets+tls/ssl) protocol - corrupted messages would not be decrypted well. 使用wss(websockets + tls / ssl)协议 - 损坏的消息不会被很好地解密。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM