Introduction

    • a Node.js server: Source |
    • a Javascript client library for the browser (which can be also run from Node.js): Source |

    There are also several client implementation in other languages, which are maintained by the community:

    Other server implementations:

    The client will try to establish a WebSocket connection if possible, and will fall back on HTTP long polling if not.

    WebSocket is a communication protocol which provides a full-duplex and low-latency channel between the server and the browser. More information can be found .

    • the browser supports WebSocket (97% of all browsers in 2020)
    • there is no element (proxy, firewall, …) preventing WebSocket connections between the client and the server

    you can consider the Socket.IO client as a “slight” wrapper around the WebSocket API. Instead of writing:

    You will have, on the client-side:

    The API on the server-side is similar, you also get a object which extends the Node.js class:

    Socket.IO provides additional features over a plain WebSocket object, which are listed below.

    But first, let’s detail what the Socket.IO library is not.

    If you are looking for a plain WebSocket server, please take a look at or uWebSockets.js.

    There are also to include a WebSocket server in the Node.js core.

    On the client-side, you might be interested by the robust-websocket package.

    Here are the features provided by Socket.IO over plain WebSockets:

    • reliability (fallback to HTTP long-polling in case the WebSocket connection cannot be established)
    • automatic reconnection
    • acknowledgments
    • broadcasting or to a subset of clients (what we call “Room”)
    • (what we call “Namespace”)

    Please find more details about how it works here.