Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket.io client fails to reconnect to server after an abrupt disconnection

I am using the socket.io NodeJs server library and the Swift client library. Majority of the time the client successfully reconnects to the server after a disconnection, however intermittently we are seeing abrupt disconnections and then the client is never able to reconnect.

In the server logs, I see the client sending a connection attempt at the defined re-try interval, however it just never successfully establishes the connection and then we get a ping timeout.

There is surprisingly very little support for Socket.io which makes this extremely difficult to solve.

like image 970
McLovin Avatar asked Oct 30 '22 07:10

McLovin


1 Answers

I figured out a solution to our problem by forcing a new engine to be created in the client upon reconnections. When creating the SocketIOClient object, set the forceNew variable to true which allows the client to create a new engine and thus always successfully establishes the connection.

return SocketIOClient(socketURL: socketURL, config: [.forceNew(true)])
like image 183
McLovin Avatar answered Nov 15 '22 06:11

McLovin