Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Old socket listeners not destroyed when I connect a new socket with previous ip and port #405

Open
sdjalft opened this issue Jan 14, 2025 · 0 comments

Comments

@sdjalft
Copy link

sdjalft commented Jan 14, 2025

PinusSocketioClient(
      ip,
      13100,
      onConnect: (client) {
        client.request([
          apiMap.GATE_getTargetConnector,
          ({
            'roomId': roomId,
          } as Map<String, dynamic>),
          (data) {
            client.disconnect();
            completer.complete((port: data['port']) as ({
              int port
            }));
          }
        ]);
      },
      onError: (err, client) {
        Toast.show('error:$err');
        client.disconnect();
        if (!completer.isCompleted) {
          completer.complete((port: 0));
        }
      },
      onDisconnect: (client) {
        client.disconnect();
        if (!completer.isCompleted) {
          completer.complete((port: 0));
        }
      },
    );

here is my socket client code. and when socket error, I try to create a new Socket like this.

when socket error again, the onError Event called twice. The first time that event called,client's hashCode equals destroyed client's hashcode.

Here is my dispose code:

void disconnect() {
    _socket.disconnect();
    _socket.dispose();
    _socket.close();
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant