TerminalX / server.js
Kano001's picture
Update server.js
971fc9c verified
raw
history blame
630 Bytes
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`);