O'Reilly logo

Socket.IO Cookbook by Tyson Cadenhead

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required