socket.io-client-java icon indicating copy to clipboard operation
socket.io-client-java copied to clipboard

Client socket.io doesn't receive any messages

Open rearAdmiralDuck opened this issue 2 years ago • 3 comments

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:

  • Device: PC
  • OS: Windows 10

rearAdmiralDuck avatar May 31 '22 08:05 rearAdmiralDuck

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

liangyuanpeng avatar Jun 24 '22 15:06 liangyuanpeng

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.

sumit-s-fltcase avatar Jul 22 '22 06:07 sumit-s-fltcase

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

liangyuanpeng avatar Dec 11 '22 08:12 liangyuanpeng