File size: 630 Bytes
971fc9c 5750188 971fc9c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
const { WebSocketServer } = require('ws');
// Create a WebSocket server listening on port 443
const sockserver = new WebSocketServer({ port: 443 });
sockserver.on('connection', ws => {
console.log('New client connected!');
ws.send('connection established');
ws.on('close', () => console.log('Client has disconnected!'));
ws.on('message', data => {
sockserver.clients.forEach(client => {
console.log(`distributing message: ${data}`);
client.send(`${data}`);
});
});
ws.onerror = function () {
console.log('websocket error');
};
});
console.log(`WebSocket server listening on port 443`);
|