1

In case of multiple socket.io servers (ALB balanced) client is getting connected and disconnected from both the nodes giving 'transport error'. Ideally it should be connected to one node and remain connected to that node. In case of one node in ALB, connection is remaining persistent. Any help??

Vikas Goyal
  • 131
  • 2
  • 11

3 Answers3

1

By default, when socket.io first starts up, it starts up in http polling mode. After a few sequential http requests, and an OK check on capabilities at both ends, it will then switch to webSocket mode. This is done in order to make a working connection first and then determine if webSockets are supported on both ends and, if so, then switch to using the webSocket. If you have a non-sticky load balancer, then you could indeed have a problem with the first few http polling requests ending up on different servers which would probably break how socket.io works since a single server would be missing some of the connections in the startup sequence.

You can either configure your load balancers to be sticky so they always send the same client to the same server or you can tell socket.io that you only want it to connect in webSocket mode.

To configure socket.io to only use a webSocket and no polling (so just one connection), you can set a configuration option in the client as seen here:

Socket.io 1.x: use WebSockets only?

Keep in mind that socket.io has auto-connect logic so that if sometime long after your establish your socket.io connection to the server, the connection stops working for some reason, the client will drop the current connection and attempt to make a new one. If you're still using a non-sticky load balancer, then that reconnect may end up on a different server. Depending upon what you're doing on the server that may or may not be a problem. Sticky load balancing would make sure that the reconnect ends up on the same server.

Community
  • 1
  • 1
jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • 1
    any demerits of using connection directly using transport as websocket rather than polling? – Vikas Goyal Feb 27 '17 at 10:58
  • @VikasGoyal - If you run in a browser that does not support webSockets, then you will not get a connection. socket.io would normally handle that condition by substituting http polling in place of the missing webSocket. – jfriend00 Feb 27 '17 at 20:53
0

Use 0.8.3 version of io.socket Remove new version 1.0.0

compile('io.socket:socket.io-client:0.8.3') {
    exclude group: 'org.json', module: 'json'
}

this is worked for me

Pankaj Talaviya
  • 3,328
  • 28
  • 31
-1

Use below version of io.socket after removing the old version: https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js

It works for me!

Meloman
  • 3,558
  • 3
  • 41
  • 51