mrniko / netty-socketio

Socket.IO server implemented on Java. Realtime java framework
Apache License 2.0
6.82k stars 1.65k forks source link

The client keeps on reconnecting #614

Open hungthuanmk opened 6 years ago

hungthuanmk commented 6 years ago

I am trying to make communication between Server (Java) and React Native App on phone It works well with Server written in Node.js but the client keep retrying to connect to server written in Java with netty-socketio ver 1.7.16 Here is my code:

public static void main(String[] args) {
        Configuration config = new Configuration();
        config.setPort(3000);
        final SocketIOServer server = new SocketIOServer(config);

        server.addEventListener("msg", String.class, new DataListener<String>() {
            public void onData(SocketIOClient client, String data, AckRequest ackRequest) {
                System.out.println("Received: " + data);
            }
        });

        server.addConnectListener(new ConnectListener() {
            public void onConnect(SocketIOClient socketIOClient) {
                System.out.println(socketIOClient.getSessionId() + " had just connected!");
                socketIOClient.joinRoom("room1");
            }
        });

        server.start();

        while (true) {
            server.getBroadcastOperations().sendEvent("img","This is msg from server");
        }
        server.stop();
    }

And here is console output when react native app run image

hangsucho commented 5 years ago

Check your client transport. If you set polling, websocket.

First, connect HTTP long-polling. After client will be try connect websocket.

see this page. https://socket.io/docs/client-api/#With-websocket-transport-only

mkjiau commented 5 years ago

any update on this issue?

dhavalsoni2001 commented 5 years ago

@mkjiau @hangsucho solution works perfectly.