@@ -255,14 +255,13 @@ server.listen(8080);
255
255
``` js
256
256
const http = require (' http' );
257
257
const WebSocket = require (' ws' );
258
- const url = require (' url' );
259
258
260
259
const server = http .createServer ();
261
260
const wss = new WebSocket.Server ({ noServer: true });
262
261
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} ` );
266
265
});
267
266
});
268
267
@@ -272,6 +271,7 @@ server.on('upgrade', function upgrade(request, socket, head) {
272
271
socket .destroy ();
273
272
return ;
274
273
}
274
+
275
275
wss .handleUpgrade (request, socket, head, function done (ws ) {
276
276
wss .emit (' connection' , ws, request, client);
277
277
});
@@ -281,8 +281,7 @@ server.on('upgrade', function upgrade(request, socket, head) {
281
281
server .listen (8080 );
282
282
```
283
283
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 ` .
286
285
287
286
### Server broadcast
288
287
@@ -477,14 +476,15 @@ We're using the GitHub [releases][changelog] for changelog entries.
477
476
478
477
[ MIT] ( LICENSE )
479
478
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
485
479
[ 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
486
482
[ node-zlib-bug ] : https://github.com/nodejs/node/issues/8871
487
483
[ node-zlib-deflaterawdocs] :
488
484
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
489
489
[ ws-server-options] :
490
490
https://github.com/websockets/ws/blob/master/doc/ws.md#new-websocketserveroptions-callback
0 commit comments