diff --git a/README.md b/README.md index 8d3518b..509824d 100644 --- a/README.md +++ b/README.md @@ -161,9 +161,25 @@ console.log(results.tlsServers); Note: you don't need to create websockets for the plain ports. -``` +```javascript +var WebSocketServer = require('ws').Server; + results.tlsServers.forEach(function (server) { + var wss = new WebSocketServer({ server: server }); + wss.on('connection', onConnection); }); + +function onConnection(ws) { + var location = url.parse(ws.upgradeReq.url, true); + // you might use location.query.access_token to authenticate or share sessions + // or ws.upgradeReq.headers.cookie (see http://stackoverflow.com/a/16395220/151312) + + ws.on('message', function incoming(message) { + console.log('received: %s', message); + }); + + ws.send('something'); +} ``` ## API