gpt4 book ai didi

websocket - 一个数据包可以包含多个Websocket吗?

转载 作者:行者123 更新时间:2023-12-02 17:37:04 30 4
gpt4 key购买 nike

当我注意到这种框架时,我正在使用 Wireshark 检查我的服务器和浏览器之间的 websocket 流量:

No.     Time           Source          Destination   Protocol  Length Info
144342 8212.033150000 127.0.0.1 127.0.0.1 WebSocket 821 WebSocket Text [FIN]

Frame 144342: 821 bytes on wire (6568 bits), 821 bytes captured (6568 bits) on interface 0
Ethernet II, Src: 00:00:00_00:00:00 (00:00:00:00:00:00), Dst: 00:00:00_00:00:00 (00:00:00:00:00:00)
Internet Protocol Version 4, Src: 127.0.0.1 (127.0.0.1), Dst: 127.0.0.1 (127.0.0.1)
Transmission Control Protocol, Src Port: http-alt (8080), Dst Port: 53749 (53749), Seq: 1132, Ack: 603, Len: 755
WebSocket
1... .... = Fin: True
.000 .... = Reserved: 0x00
.... 0001 = Opcode: Text (1)
0... .... = Mask: False
.111 1110 = Payload length: 126 Extended Payload Length (16 bits)
Extended Payload length (16 bits): 140
Payload
Text: {"type":"COLLABORATIVE_COMMANDS","remoteUser":"null","key":"1c78c08f-5d2d-445a-a63c-3a211d2f0336","messageBroadcast":{"smartPath":["null"]}}
WebSocket
1... .... = Fin: True
.000 .... = Reserved: 0x00
.... 0001 = Opcode: Text (1)
0... .... = Mask: False
.111 1110 = Payload length: 126 Extended Payload Length (16 bits)
Extended Payload length (16 bits): 329
Payload
Text [truncated]: {"type":"COLLABORATIVE_COMMANDS","remoteUser":"","key":"1c78c08f-5d2d-445a-a63c-3a211d2f0336","messageBroadcast":{"cameraInfos":{"target":{"x":0,"y":0,"z":0},"camPos":{"x":557.0133301398326,"y":159.5460628202445,"z":342.4
WebSocket
1... .... = Fin: True
.000 .... = Reserved: 0x00
.... 0001 = Opcode: Text (1)
0... .... = Mask: False
.111 1110 = Payload length: 126 Extended Payload Length (16 bits)
Extended Payload length (16 bits): 141
Payload
Text: {"type":"COLLABORATIVE_COMMANDS","remoteUser":"","key":"1c78c08f-5d2d-445a-a63c-3a211d2f0336","messageBroadcast":{"colourEditedMeshes":true}}
WebSocket
1... .... = Fin: True
.000 .... = Reserved: 0x00
.... 0001 = Opcode: Text (1)
0... .... = Mask: False
.111 1110 = Payload length: 126 Extended Payload Length (16 bits)
Extended Payload length (16 bits): 129
Payload
Text: {"type":"COLLABORATIVE_COMMANDS","remoteUser":"","key":"1c78c08f-5d2d-445a-a63c-3a211d2f0336","messageBroadcast":{"explode":"0"}}

这是否意味着我的数据包中有多个 websocket?这怎么可能?

最佳答案

如果您阅读 WebSocket 规范,RFC 6455 ,您会看到 WebSocket 数据包是成帧的,其中每个帧都有自己的 header 和有效负载。请记住,TCP 是一种流式传输。发送方和接收方并不关注 TCP 帧,他们关注的是这些帧中的有效载荷。 WebSocket 发送方将发送一个 WebSocket header ,然后是其有效负载,然后是下一个 WebSocket header 及其有效负载,依此类推。 WebSocket 接收器将读取 WebSocket header 及其有效负载,然后读取下一个 WebSocket header 及其有效负载,依此类推。通常,Nagle algorithm在 TCP 套接字上启用,它将根据需要将应用程序数据拆分和组合到 TCP 帧中,以实现高效的网络传输。这是由对应用程序透明的 TCP 堆栈处理的。所以是的,可以看到多个 WebSocket 帧出现在单个 TCP 帧内,如果 Nagle 决定以这种方式传输它们的话。如果 WebSocket 数据包在短时间内发送,Nagle 可能会合并它们,因此它只需要传输单个 TCP 帧而不是单独的 TCP 帧。

关于websocket - 一个数据包可以包含多个Websocket吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25384801/

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