layout: post title: Socket IO date: 2019-02-12 —
Socket.IO
Is a library that enables real-time, bidirectional and event-based communication between the browser and the server. It consists of:
-
a Node.js server: Source API -
a Javascript client library for the browser (which can be also run from Node.js): Source API
Reliability
Connections are established even in the presence of:
-
proxies and load balancers.
-
personal firewall and antivirus software.
-
For this purpose, it relies on Engine.IO, which first establishes a long-polling connection, then tries to upgrade to better transports that are “tested” on the side, like WebSocket. Please see the Goals * section for more information.
example
io.on(‘connection’, function(socket){ socket.emit(‘request’, /* /); // emit an event to the socket io.emit(‘broadcast’, / /); // emit an event to all connected sockets socket.on(‘reply’, function(){ / */ }); // listen to the event });