Skip to content

Instantly share code, notes, and snippets.

@enjalot
Created July 11, 2015 19:08
Show Gist options
  • Save enjalot/3f8707a6df528154bfcd to your computer and use it in GitHub Desktop.
Save enjalot/3f8707a6df528154bfcd to your computer and use it in GitHub Desktop.
basic websocket usage
var ws = new WebSocket("ws://54.235.119.124:8000/");
// On successful connection
ws.onopen = function(event) {
console.log("Open");
ws.send("eye");
};
// On message received
ws.onmessage = function(event) {
console.log("got leap data", console.log(event.data));
var json = JSON.parse(event.data)
console.log(json)
};
// On socket close
ws.onclose = function(event) {
ws = null;
}
//On socket error
ws.onerror = function(event) {
console.error("Received error");
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment