socketio / socket.io-client-java

Full-featured Socket.IO Client Library for Java, which is compatible with Socket.IO v1.0 and later.
https://socketio.github.io/socket.io-client-java/installation.html
Other
5.32k stars 972 forks source link

Client socket.io doesn't receive any messages #713

Open rearAdmiralDuck opened 2 years ago

rearAdmiralDuck commented 2 years ago

Describe the bug I'm trying to reach the python-based server via java-based Socket.IO client. While the connection is successful (detected by catching EVENT_OPEN and EVENT_CONNECT events), no other responses from the server are detected.

To Reproduce

Socket.IO server version: presumably 4

Socket.IO java client version: 2.0.2

Client

public class MyApplication {
    public static void main(String[] args) throws URISyntaxException {
        URI uri = URI.create("http://www.example.com");
        IO.Options op = new Options();
    op.transports = new String[] {WebSocket.NAME};
    op.reconnection = false;
    op.upgrade = true;

    // create socket
    socket = IO.socket(uri, op);

        // make subscriptions
    socket.on(Socket.EVENT_CONNECT, args -> {
        System.out.println("connected " + Arrays.toString(args));

        // send authentication on connection
        String token = "let-me-in";
        sendContent("authenticate", token);
    });
    socket.io().on(Manager.EVENT_OPEN, args -> {
                // works
        System.out.println("connection opened " + Arrays.toString(args));
    });
    socket.on("topic", args -> {
                // doesn't work
        System.out.println("interesting data: " + Arrays.toString(args));
    });

    // connect the socket
    socket.connect();
    }

   public static void sendContent(String operation, Object content) {
    socket.emit(operation, content, (Ack) args -> {
        if (args.length > 0) {
                        // expected {response : ok} or something similar
            String response = args[0].toString();
            System.out.println(operation + " response: " + response);
        } else {
                        // I always get this reponse instead
            System.out.println("empty " + operation + " response!");
        }
    });
    }
}

Expected behavior I expected this to open the connection, receive the authorization response, and based on the success of that to further receive the "topic" events. When I tested it on local python eventlet server it works nicely, but I can't get any response from the real one outside of connection opened [], connected [] and empty authenticate response!.

Platform:

liangyuanpeng commented 2 years ago

so do you confirmed that your server is really send event to your client?

sumit-s-fltcase commented 2 years ago

For me in one application on function event isteners are working fine. But in another application on function listeners are working only in debug mode.

liangyuanpeng commented 1 year ago

@sumit-s-fltcase I can check it if you have some code to reproduce it.