sunsus / socket.io-java-emitter

A Java implementation of socket.io-emitter
MIT License
15 stars 11 forks source link

Compactibility issue with netty socketio #6

Open vishnu-chalil opened 3 years ago

vishnu-chalil commented 3 years ago

I created a server with netty socketio and added the clients to few rooms. I have configured reddison for redis to replace in memory store. The joining is done as shown below.

    @OnEvent(value = "join")
    public void onJoin(SocketIOClient client, AckRequest request, JSONObject jsonObject) {
        client.joinRoom(jsonObject.getString("email"));

}

The client has an onEvent Listener as follows on browser side to listen to events

                socket.on("new_msg", function(data) {
                        console.log("room data: ", data);
                });

When I use the netty socket server I'm able to send data as follows.

        socketIOServer.getRoomOperations("user1@example.com").sendEvent("new_msg", "{\"msg\": \"hello\"}");

But when I send data using the this emitter class I'm not able to send data and there are neither errors. I tried to send as below.

            HashMap<String,String> opts = new HashMap<String,String>();
            opts.put("host", "127.0.0.1");
            opts.put("port", "6379");
            Emitter emitter = Emitter.getInstance(null, opts);
            emitter.of("/").to("user1@example.com").emit("new_msg", "{\"msg\": \"emitted\"}");

So I inspected the data flowing through redis PSUBSCRIBE * and the result of both operations are different.

This is how data send using this package looks like.

1) "pmessage"
2) "*"
3) "socket.io#/#user1@example.com#"
4) "\x93\xa7emitter\x83\xa4type\x02\xa4data\x92\xa7new_msg\xb2{\"msg\": \"emitted\"}\xa3nsp\xa1/\x82\xa5rooms\x91\xb1user1@example.com\xa5flags\x80"

and this is how the data send using the original netty server send command looks like.

1) "pmessage"
2) "*"
3) "dispatch"
4) "\x04\x04\t>8com.corundumstudio.socketio.store.pubsub.DispatchMessage\\\xde\xed\xf1\x9dx'\x8d\x00\x00\x00\x03>\tnamespace\x16\x00>\x06packet\x16\x00>\x04room\x16\x00\t>6com.corundumstudio.socketio.store.pubsub.PubSubMessage\x86\x05\xfb\x03\xb5\x92\xca\xc5\x00\x00\x00\x01>\x06nodeId\x16\x00\x16L\x00\x00\x00\x00\x00\r.\xca=\x04\t>+com.corundumstudio.socketio.protocol.Packet?H\xf0\xf0\x0bf\x80\x82\x00\x00\x00\t>\x05ackId\x16\x00>\x0battachments\x16\x00>\x10attachmentsCount#\x00>\x04data\x16\x00>\ndataSource\x16\x00>\x04name\x16\x00>\x03nsp\x16\x00>\asubType\x16\x00>\x04type\x16\x00\x16\x01]\x00\x00\x00\x00\x04\t>\x1ajava.util.Arrays$ArrayList\xd9\xa4<\xbe\xcd\x88\x06\xd2\x00\x00\x00\x01>\x01a\x16\x00\x16B\x01\x16>\x10{\"msg\": \"hello\"}\x01>\anew_msg=\x04\x0c\x00\x00\x00/com.corundumstudio.socketio.protocol.PacketType\x00\x00\x00\x05EVENT\x04;\xff\x00\x00\x00\aMESSAGE>\x11user1@example.com"

The content seems to differ a lot. Could this be the issue? Any idea on what's happening here? Is there any possible resolution methods that can be done? Or am I totally doing something wrong.

rishi023 commented 3 years ago

I too am facing the exactly same issue? Did you find any solution @vishnu-chalil ?

vishnu-chalil commented 3 years ago

@rishi023 I had to change the source code. But still error exists. Currently the code emits to socket.io#/#user1@example.com# channel in this format. Changing the channel to dispatch by editing Emiiter.java helps detects the message but again a key error occurs while reading, probably beacuse I used reddison as redis client in netty-socketio and Jedis with this package. Haven't checked it after that. Probably due to the format in payload is send by this package might be causing the key error or maybe because of Jedis and Reddison compactibility issue. Not sure