forked from modelcontextprotocol/java-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
21 lines (16 loc) · 666 Bytes
/
server.js
File metadata and controls
21 lines (16 loc) · 666 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Import the WebSocket package
const WebSocket = require('ws');
// Set up the WebSocket server to listen on port 8080
const wss = new WebSocket.Server({ port: 8080 });
// When a new WebSocket connection is established
wss.on('connection', function connection(ws) {
console.log('New client connected');
// When a message is received from the client
ws.on('message', function incoming(message) {
console.log('received: %s', message);
});
// Send a welcome message to the client
ws.send('Welcome to the WebSocket server!');
});
// Log the WebSocket server start
console.log('WebSocket server is listening on ws://localhost:8080');