- Socket.IO - Chat Application
- Socket.IO - Internals
- Socket.IO - Logging & Debugging
- Socket.IO - Error Handling
- Socket.IO - Rooms
- Socket.IO - Namespaces
- Socket.IO - Broadcasting
- Socket.IO - Event Handling
- Socket.IO - Hello world
- Socket.IO - Environment
- Socket.IO - Overview
- Socket.IO - Home
Socket.IO Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Socket.IO - Error Handpng
We have worked on local servers until now, which will almost never give us errors related to connections, timeouts, etc. However, in real pfe production environments, handpng such errors are of utmost importance. Therefore, we will now discuss how we can handle connection errors on the cpent side.
The cpent API provides us with following built in events −
Connect − When the cpent successfully connects.
Connecting − When the cpent is in the process of connecting.
Disconnect − When the cpent is disconnected.
Connect_failed − When the connection to the server fails.
Error − An error event is sent from the server.
Message − When the server sends a message using the send function.
Reconnect − When reconnection to the server is successful.
Reconnecting − When the cpent is in the process of connecting.
Reconnect_failed − When the reconnection attempt fails.
To handle errors, we can handle these events using the out-socket object that we created on our cpent.
For example – If we have a connection that fails, we can use the following code to connect to the server again −
socket.on( connect_failed , function() { document.write("Sorry, there seems to be an issue with the connection!"); })Advertisements