'Why am I not receiving any subscribed topics via Socket.IO?

I am using 2.x Socket.IO Java client to reach a server that was currently updated for Socket.IO v4. I was unable to make a socket connection up until I forcibly changed the used EIO from 3 to 4 like this:

     OkHttpClient client = new OkHttpClient.Builder()
            .addInterceptor(chain -> {
                Request request = chain.request();
                // replaces the enforced EIO=3 in arguments by EIO=4 which currently works
                Request newRequest = request.newBuilder()
                        .url(request.url().url().toString().replaceAll("EIO=3", "EIO=4"))
                        .build();
                return chain.proceed(newRequest);
            })
            .build();
    
    // set uri and connection options
    URI uri = URI.create("https://example.com/socket.io/");
    IO.Options op = new Options();
    op.transports = new String[] {WebSocket.NAME};
    op.upgrade = true;
    op.callFactory = client;
    op.webSocketFactory = client;
    op.path = "/socket.io/";
    
    // create socket
    socket = IO.socket(uri, op);

    // set up listener
    socket.on("some_topic", args -> {
        // topic handling
        System.out.println(Arrays.toString(args));
    });

After that the connection was accepted and confirmed; however no events of subscribed topics were caught after that. I strongly suspect the version difference between the client and server is to blame even though the connection was successful and the official documentation (https://socketio.github.io/socket.io-client-java/installation.html#Compatibility) says it should work.

Is the problem caused by version difference? If so, why was the connection successful after all? Is there a better way to do what did, regarding the EIO? Can the problem be elsewhere?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source