doghappy / socket.io-client-csharp

socket.io-client implemention for .NET
MIT License
721 stars 124 forks source link

Does the v4 version skip the first byte when receiving binarry data? #322

Closed LevyShang closed 1 year ago

LevyShang commented 1 year ago

When inquiring about historical problems, I found that this problem has been fixed in #109, but it has been a long time since the code only judged that Options.EIO == EngineIO.V3, so the judgment of the latest v4 version here is wrong?

doghappy commented 1 year ago

we will get an extra byte if we use EngineIO.V3, but V4 not.

LevyShang commented 1 year ago

we will get an extra byte if we use EngineIO.V3, but V4 not.

不好意思,我最近刚刚了解相关内容,很多细节不是很懂,能告诉我更详细的说明吗?或者告诉我相关关键字,我可以自己去找找

doghappy commented 1 year ago

if you want to check more details:

https://github.com/doghappy/socket.io-client-csharp/blob/5a7b8e331908edcd722eca955d249d1f0e8656aa/src/SocketIOClient/Transport/WebSockets/WebSocketTransport.cs#L108-L120

LevyShang commented 1 year ago

if you want to check more details:

https://github.com/doghappy/socket.io-client-csharp/blob/5a7b8e331908edcd722eca955d249d1f0e8656aa/src/SocketIOClient/Transport/WebSockets/WebSocketTransport.cs#L108-L120

我知道这段代码,但是我想知道首位这个意外byte是哪里出来的,之前看socket.io文档,我的理解是event 04 ,但是您刚才解释只有eio.v3才有这个byte,所以我比较奇怪,想知道是我哪里理解错了吗?现在我的情况是没有这个首字节我无法解析收到的二进制内容,服务器也无法处理我发送的数据

doghappy commented 1 year ago

如果运行 socket.io v2 server,此版本的使用的 eio3, 当使用 websocket 协议发送 binary 数据时,服务端会多发一个额外的 byte,并且,客户端在向服务器发送 binary 时,也需要添加这个多余的 byte,不然服务器解析不了,这个 byte 就是 4.

https://github.com/doghappy/socket.io-client-csharp/blob/5a7b8e331908edcd722eca955d249d1f0e8656aa/src/SocketIOClient/Transport/WebSockets/WebSocketTransport.cs#L34-L40

在传输数据时,客户端和服务端会隐藏复杂的信息,包括额外的byte,一般情况下上层应用甚至不知道他的存在。

另外,你所说的 event 04,我没有遇到过,是你说错了吗?我知道的有 40 42 等等

40{"sid":"xO_jp2_xrGtXUveLAc4y"}
42["hi","onAny"]

40表示连接成功 42表示event消息

LevyShang commented 1 year ago

我说的就是4,你这么说我就能理解了,我去跟负责server端的协同了解下看看他server真正的版本是什么,感谢解答