Handling connection timeouts

When we perform a real-time application development, it is important to be aware of when the server-side WebSocket connection is dropped, and we will no longer be able to communicate with our server. This allows you to provide an offline mode for our apps, where we can keep a record of all the events that need to be emitted to the server once the connection is re-established.

Socket.IO has some really great built-in functionalities to re-establish the connection once it has been dropped. This is accomplished by creating recurring polling requests to the server until a new connection is found or until the number of reconnection attempts we allow are exceeded.

Getting ready

For this recipe, we will use Express to serve ...

Get Socket.IO Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.