File size: 511 Bytes
f5fc3f3
44f12da
f5fc3f3
44f12da
f5fc3f3
 
44f12da
f5fc3f3
 
 
 
 
 
 
 
 
 
44f12da
f5fc3f3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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');