implement a model of WebSocket and ws based on the EventEmitter model

This commit is contained in:
Erik Krogh Kristensen
2020-01-12 15:42:54 +01:00
parent 007b0795ec
commit b526a2ea0f
7 changed files with 266 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
(function () {
const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 8080 });
wss.on('connection', function connection(ws) {
ws.on('message', function incoming(message) {
console.log('received: %s', message);
});
ws.send('Hi from server!');
});
})();