Skip to content

Unable to stop automatic reconnection attempts #413

Description

@solofx

I've got some code that establishes a connection to my socket.IO server, which works perfectly well and allows messages to transit back and forth. The connection is established with auto-reconnection enabled for fault tolerance.

void connectToSocket() {
  IO.Socket socket = IO.io(socketUrl,
    IO.OptionBuilder()
      .setTransports(['websocket'])
      .enableAutoConnect()
      .enableReconnection()
      .build()
  );

}

I have functionality within my application for the user to change the connection URL to switch servers. When this happens, I need to disconnect the existing connection, prevent any re-connection attempts and establish a replacement connection.

I've tried calling various methods to terminate the existing connection, however the reconnection attempts persist in the background, even once the replacement connection has been established. For example:

socket.disconnect();
socket.close();
socket.clearListeners();

connectToSocket();

So far the only way to effectively stop the connection attempts is to terminate the application, which seems a little extreme. Am I missing something or is this expected functionality? If so, does an approach exist to stop an automatically reconnecting socket instance?

My version of the socket.io client is "2.0.3"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions