-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add better examples with local echo server
- Loading branch information
Showing
3 changed files
with
6 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
const WebSocket = require('ws') | ||
|
||
console.log('open the file ' + process.cwd() + '/examples/example.html in a browser') | ||
const wss = new WebSocket.Server({ port: 8080 }) | ||
|
||
wss.on('connection', function connection (ws) { | ||
console.log('connection') | ||
ws.on('message', function incoming (message) { | ||
console.log('received: %s', message) | ||
ws.send(message) | ||
console.log('echoed back...') | ||
}) | ||
|
||
ws.send('something') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters