Kuba T
Kuba T

Reputation: 3083

Reset Socket.io Client connection

I write a Google Chrome Extension that uses Socket.io capabilities. More precisely, it's an AngularJS app with angular-socket.io on board.

I allow users to set up socket.io server address and port in the options page. Everything works fine until a user wants to change the address because I don't know how to reset the Socket.io connection. Ideally, I would like to close previous connection and reconnect with new connection without restarting the app (remember, it's an Chrome Extension, I cannot restart it by itself).

So my question is: How to reset the Socket.io client connection and reconnect with new DSN?

PS. I'm using socket.io-client#1.3.6

Upvotes: 1

Views: 2936

Answers (1)

supergicko
supergicko

Reputation: 61

You are using angular-socket.io, so you inject socket.io (with a given config) as a service into your angular app. Assuming your service is called socketIOService you can do following:

  • Disconnect on client-side with socketIOService.disconnect();
  • Reconnect with socketIOService.connect(SERVER_IP, {'force new connection': true});

Upvotes: 2

Related Questions