netty-socketio icon indicating copy to clipboard operation
netty-socketio copied to clipboard

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

Open goodenp opened this issue 1 year ago • 7 comments

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?

goodenp avatar Nov 10 '23 01:11 goodenp

https://github.com/mrniko/netty-socketio/issues/935#issue-1939984463

Maybe the same problem. @mrniko

juteman avatar Nov 10 '23 01:11 juteman

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

xuhaoyang avatar Jan 10 '24 08:01 xuhaoyang

怎么解决呢

bwcx728 avatar Mar 12 '24 03:03 bwcx728

怎么解决呢

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

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

juteman avatar Mar 13 '24 09:03 juteman

怎么解决呢

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

xuhaoyang avatar Mar 13 '24 11:03 xuhaoyang

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

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

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

liy-cn avatar Mar 20 '24 08:03 liy-cn

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

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

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

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

xuhaoyang avatar Mar 20 '24 08:03 xuhaoyang

这个问题很久了,还没修复,考虑弃用这个组件了

LostStar110 avatar Jul 12 '24 06:07 LostStar110