const WebSocket = require('ws'); | |
const wss = new WebSocket.Server({ port: 7860 }); | |
wss.on('connection', function connection(ws) { | |
console.log('A new client connected!'); | |
ws.on('message', function incoming(message) { | |
console.log('Received:', message); | |
// Echo the message back to the client | |
ws.send(`Server received: ${message}`); | |
}); | |
ws.on('close', function () { | |
console.log('Client has disconnected'); | |
}); | |
}); | |
console.log('WebSocket server is listening on ws://localhost:8080'); | |