On connecting with socket using socket.io it's returning disconnected socket object intermittently

263 Views Asked by At

I am using socket.io to establish a socket connection. The server i am trying to establish connection with is first behind a Amazon ELB then a HAProxy load balancer. I am using this code:

socket = io.connect(url, {
  'path': exports.baseURL + "socket.io",
  'resource': resource,
  'max reconnection attempts': 3,
  'sync disconnect on unload' : false,
  'transports' : ['websocket']
});

Almost half of the times this call is returning the valid socket object but other times it's returning disconnected socket object of this type:

Socket
  _callbacks:Object
  acks:Object
  connected:false
  disconnected:true
  ids:0
  io:Manager
  json:Socket
  nsp:"/"
  receiveBuffer:Array[0]
  sendBuffer:Array[0]
  subs:Array[3]

Main this here to notice is here connected:false and disconnected:true means the connection is not getting established. Can someone please help here?

0

There are 0 best solutions below