const WebSocket = require('ws'); const server = new WebSocket.Server({ port: 8080 }); server.on('connection', (socket) => { console.log('Client connected'); socket.on('message', (data) => { console.log(`Received message: ${data}`); server.clients.forEach((client) => { if (client !== socket && client.readyState === WebSocket.OPEN) { client.send(data); } }); }); socket.on('close', () => { console.log('Client disconnected'); }); });In this example, the WebSocket server listens on port 8080, and clients can connect to it to send and receive messages. The `on('connection')` method is called whenever a new client connects to the WebSocket server. Inside the `on('message')` method, we loop through all connected clients and send the message to any clients that are not the sender and are currently connected. The package library used in this example is the ws package, which is a WebSocket library for Node.js.