Skip to content

Instantly share code, notes, and snippets.

@ajitsinghkamal
Created January 31, 2018 13:55
Show Gist options
  • Save ajitsinghkamal/e6b596549c7e3f463c26b12008007b1a to your computer and use it in GitHub Desktop.
Save ajitsinghkamal/e6b596549c7e3f463c26b12008007b1a to your computer and use it in GitHub Desktop.
establish websocket connection over websocket protocol
// use a websocket object
// uses websocket API
const socket = new WebSocket('ws url', [supported protocols])
//set up an event listener for incoming messages
socket.onmessage = (event) => {
//do something
console.log(event.data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment