Skip to content

Instantly share code, notes, and snippets.

@Srushtika
Created November 16, 2018 14:41
Show Gist options
  • Save Srushtika/f5316e3ee650e2463cdc0262ce1a2c0a to your computer and use it in GitHub Desktop.
Save Srushtika/f5316e3ee650e2463cdc0262ce1a2c0a to your computer and use it in GitHub Desktop.
WebSockets server tutorial
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