@@ -255,14 +255,13 @@ server.listen(8080);
255255``` js
256256const http = require (' http' );
257257const WebSocket = require (' ws' );
258- const url = require (' url' );
259258
260259const server = http .createServer ();
261260const wss = new WebSocket.Server ({ noServer: true });
262261
263- wss .on (' connection' , function (ws , request , client ) {
264- ws .on (' message' , function ( message ) {
265- console .log (` WS message ${ message } from user ${ client} ` );
262+ wss .on (' connection' , function connection (ws , request , client ) {
263+ ws .on (' message' , function message ( msg ) {
264+ console .log (` Received message ${ msg } from user ${ client} ` );
266265 });
267266});
268267
@@ -272,6 +271,7 @@ server.on('upgrade', function upgrade(request, socket, head) {
272271 socket .destroy ();
273272 return ;
274273 }
274+
275275 wss .handleUpgrade (request, socket, head, function done (ws ) {
276276 wss .emit (' connection' , ws, request, client);
277277 });
@@ -281,8 +281,7 @@ server.on('upgrade', function upgrade(request, socket, head) {
281281server .listen (8080 );
282282```
283283
284- Also see the provided [ example] ( ./examples/express-session-parse ) using
285- ` express-session ` .
284+ Also see the provided [ example] [ session-parse-example ] using ` express-session ` .
286285
287286### Server broadcast
288287
@@ -477,14 +476,15 @@ We're using the GitHub [releases][changelog] for changelog entries.
477476
478477[ MIT] ( LICENSE )
479478
480- [ https-proxy-agent ] : https://github.com/TooTallNate/node-https-proxy-agent
481- [ socks-proxy-agent ] : https://github.com/TooTallNate/node-socks-proxy-agent
482- [ client-report ] : http://websockets.github.io/ws/autobahn/clients/
483- [ server-report ] : http://websockets.github.io/ws/autobahn/servers/
484- [ permessage-deflate ] : https://tools.ietf.org/html/rfc7692
485479[ changelog ] : https://github.com/websockets/ws/releases
480+ [ client-report ] : http://websockets.github.io/ws/autobahn/clients/
481+ [ https-proxy-agent ] : https://github.com/TooTallNate/node-https-proxy-agent
486482[ node-zlib-bug ] : https://github.com/nodejs/node/issues/8871
487483[ node-zlib-deflaterawdocs] :
488484 https://nodejs.org/api/zlib.html#zlib_zlib_createdeflateraw_options
485+ [ permessage-deflate ] : https://tools.ietf.org/html/rfc7692
486+ [ server-report ] : http://websockets.github.io/ws/autobahn/servers/
487+ [ session-parse-example ] : ./examples/express-session-parse
488+ [ socks-proxy-agent ] : https://github.com/TooTallNate/node-socks-proxy-agent
489489[ ws-server-options] :
490490 https://github.com/websockets/ws/blob/master/doc/ws.md#new-websocketserveroptions-callback
0 commit comments