gpt4 book ai didi

websocket - Websocket是面向消息的吗?

转载 作者:行者123 更新时间:2023-12-02 20:58:01 24 4
gpt4 key购买 nike

我正在检查 Websocket 的行为。Websocket 与 TCP 流不同,它是面向消息的吗?

例如,当我发送数据ABC、DEF、GHI时,是否能保证收到数据ABC、DEF、GHI?在 TCP 流中,不能保证:我们可能会收到 AB、DEFG、HI。

最佳答案

是的,它是面向消息的(嗯,实际上是面向框架的)。

RFC 6455 :

After a successful handshake, clients and servers transfer data backand forth in conceptual units referred to in this specification as"messages". On the wire, a message is composed of one or moreframes. The WebSocket message does not necessarily correspond to aparticular network layer framing, as a fragmented message may becoalesced or split by an intermediary.

...

The WebSocket Protocol is designed on the principle that there shouldbe minimal framing (the only framing that exists is to make theprotocol frame-based instead of stream-based and to support adistinction between Unicode text and binary frames). It is expectedthat metadata would be layered on top of WebSocket by the applicationlayer, in the same way that metadata is layered on top of TCP by theapplication layer (e.g., HTTP).

Conceptually, WebSocket is really just a layer on top of TCP thatdoes the following:

  • adds a web origin-based security model for browsers

  • adds an addressing and protocol naming mechanism to supportmultiple services on one port and multiple host names on one IPaddress

  • layers a framing mechanism on top of TCP to get back to the IPpacket mechanism that TCP is built on, but without length limits

  • includes an additional closing handshake in-band that is designedto work in the presence of proxies and other intermediaries

关于websocket - Websocket是面向消息的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39575716/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com