Websockets in nodejs
WebSockets provide a full-duplex (two-way) communication channel over a single, long-lived TCP connection. Unlike HTTP, which is request-response, WebSockets allow the server to push data to the client in real-time. Libraries like Socket.IO are commonly used in Node.js to handle reconnection and fallbacks.
Example
// Server (Socket.io)
io.on('connection', (socket) => {
socket.emit('message', 'Hello Client!');
});Establishing a real-time connection where server emits an event to the client.