Read 17 Socket io - 401-advanced-javascript-hanna-alemu/seattle-javascript-401d31 GitHub Wiki

What is Socket IO?

Socket.IO enables real-time bidirectional event-based communication. It works on every platform, browser or device, focusing equally on reliability and speed. Socket.IO is built on top of the WebSockets API (Client side) and Node.js. It is one of the most depended upon library on npm (Node Package Manager).

Difference Between WebSocket vs Socket.io

WebSocket :

It is the communication Protocol which provides bidirectional communication between the Client and the Server over a TCP connection, WebSocket remains open all the time so they allow the real-time data transfer. When clients trigger the request to the Server it does not close the connection on receiving the response, it rather persists and waits for Client or server to terminate the request.

Key features of WebSocket :

WebSocket helps in real-time communication between the Client and the web server. This protocol helps in transforming to cross-platform in a real time world between the server and the client. This also enables the business around the world for real-time web application to enhance and to increase the feasibility. The major advantage it stands over an HTTP connection that it provides full duplex communication.

Socket.IO:

It is a library which enables real-time and full duplex communication between the Client and the Web servers. It uses the WebSocket protocol to provide the interface. Generally, it is divided into two parts, both WebSocket vs Socket.io are event-driven libraries

Client Side: it is the library that runs inside the browser

Server Side: It is the library for Node.js

Key features of Socket.IO:

  • It helps in broadcasting to multiple sockets at a time and handles the connection transparently.
  • It works on all platform, server or device ensuring the equality, reliability, and speed.
  • It automatically upgrades the requirement to WebSocket if needed.
  • It is a custom real-time transport protocol implementation on top of other protocols.
  • It requires both libraries to be used Client side as well as a server-side library.
  • IO works on work-based events. there are some reserved events which can be accessed using the Socket on server side like connect, message, Disconnect, Ping and Reconnect.

There are some Client based reserved events like Connect, connect- error, connect-timeout and Reconnect etc.

Why do we need Socket.IO:

  • I handle all the degradation of your technical alternatives to get full duplex communication in real time.
  • It also handles the various support level and the inconsistencies from the browser.
  • It also gives the additional feature room support for basic publish infrastructure and thinks like automatic reconnect.
  • Currently, AFAIK is the most used one and easier to help with vanilla web sockets.