javascript
Published on January 26, 2024By DeveloperBreeze
// Import 'ws' module
const WebSocket = require('ws');
// Create WebSocket Server on port 8080
const wss = new WebSocket.Server({ port: 8080 });
// Event listener for new connections
wss.on('connection', (ws) => {
// Event listener for incoming messages
ws.on('message', (message) => {
console.log('Received:', message);
// Send a response back to the client
ws.send('Server: ' + message);
});
});
Comments
Please log in to leave a comment.