Created
July 11, 2015 19:08
-
-
Save enjalot/3f8707a6df528154bfcd to your computer and use it in GitHub Desktop.
basic websocket usage
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
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