Created
November 16, 2018 14:41
-
-
Save Srushtika/f5316e3ee650e2463cdc0262ce1a2c0a to your computer and use it in GitHub Desktop.
WebSockets server tutorial
This file contains hidden or 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
const ws = new WebSocket('ws://localhost:3210', ['json', 'xml']); | |
ws.addEventListener('open', () => { | |
const data = { message: 'Hello from the client!' } | |
const json = JSON.stringify(data); | |
ws.send(json); | |
}); | |
ws.addEventListener('message', event => { | |
const data = JSON.parse(event.data); | |
console.log(data); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment