Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

socket.io v4.6.0 js library cannot decode binary message from netty-socketio 2.0.6 #940

Open
goodenp opened this issue Nov 10, 2023 · 7 comments

Comments

@goodenp
Copy link

goodenp commented Nov 10, 2023

byte buffer in server side before call sendEvent as below:
image

but data received by js side have a byte (value 4) more
image

then I find reason is code in EncoderHandler.handleWebsocket function line 261 ( outBuf.writeByte(4); )

for (ByteBuf buf : packet.getAttachments()) {
    ByteBuf outBuf = encoder.allocateBuffer(ctx.alloc());
    outBuf.writeByte(4);
    outBuf.writeBytes(buf);
    if (log.isTraceEnabled()) {
        log.trace("Out attachment: {} sessionId: {}", ByteBufUtil.hexDump(outBuf), msg.getSessionId());
    }
    writeFutureList.add(ctx.channel().writeAndFlush(new BinaryWebSocketFrame(outBuf)));
}

is there any solution to fix this problem?

@juteman
Copy link

juteman commented Nov 10, 2023

#935 (comment)

Maybe the same problem.
@mrniko

@xuhaoyang
Copy link

I'm having the same problem.

server data
image

client receive data
image

The array has one more bit in the header and the value is 4

@mrniko

@bwcx728
Copy link

bwcx728 commented Mar 12, 2024

怎么解决呢

@juteman
Copy link

juteman commented Mar 13, 2024

怎么解决呢

看是在客户端还是在服务端解决,服务端的话encoding的位置把那个4去掉。
客户端接到 binary数据舍弃掉第一位后面正常转化成对应的结构数据。

这里的根本问题就是binary encoding的时候开头多了个4

@xuhaoyang
Copy link

怎么解决呢

服务端的用nodejs版本去做了,走rpc到业务。

@liy-cn
Copy link

liy-cn commented Mar 20, 2024

服务器端也是一样的问题,我的解决方法是把byte[]转换成base64字符串,然后当数据传过去,客户端接受字符串,再反一下,变成byte[],就没问题了。

服务器端:
'com.corundumstudio.socketio:netty-socketio:2.0.8'

客户端:(也是java)
'io.socket:socket.io-client:2.1.0'

@xuhaoyang
Copy link

服务器端也是一样的问题,我的解决方法是把byte[]转换成base64字符串,然后当数据传过去,客户端接受字符串,再反一下,变成byte[],就没问题了。

服务器端: 'com.corundumstudio.socketio:netty-socketio:2.0.8'

客户端:(也是java) 'io.socket:socket.io-client:2.1.0'

太暴力了,这个流量会增加不少

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants