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.34k stars 977 forks source link

Client creates a new connection when it reconnects to one of the namespaces. #741

Open aperfilyev opened 1 year ago

aperfilyev commented 1 year ago

Describe the bug Let's imagine that we open two sockets to the same path but with different namespaces. Here we see only one connection with the multiplex. Everything is OK. Next, we will disconnect from one of the sockets, and after some time we will open it again. I expect no new connection will be created.

To Reproduce

Socket.IO java client version: 1.x

Client

@Test
public void namespacesTest() throws Exception {
    IO.Options opts = new IO.Options();
    opts.forceNew = false;
    opts.path = "/path";
    Socket socket1 = IO.socket(uri() + "/nsp1", opts);
    Socket socket2 = IO.socket(uri() + "/nsp2", opts);
    socket1.open();
    socket2.open();

    assertThat(socket1.io(), equalTo(socket2.io())); // passes as expected
    socket2.close();

    Socket socket3 = IO.socket(uri() + "/nsp2", opts);
    socket3.open();

    assertThat(socket1.io(), equalTo(socket3.io())); // fails as not expected

    socket1.close();
    socket3.close();
}

Expected behavior

Single connection is reused