1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| const WebSocket = require('ws');
const ws = new WebSocket.Server({ port: 8888 });
ws.on('connection', ws => { console.log('websocket connection succeeded!'); ws.send('hello, client!'); ws.on('open', msg => { console.log('websocket server open!'); });
ws.on('message', msg => { console.log('websocket server receive msg:', msg.toString()); });
ws.on('close', msg => { console.log('websocket client closed!',); }); });
|