Created
March 8, 2012 03:45
-
-
Save jessecravens/1998492 to your computer and use it in GitHub Desktop.
Basic Web Sockets
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 socket = new WebSocket('ws://html5hacks.com/socket'); | |
// Once the socket connection is opened ... send a message to the server | |
socket.onopen = function(event) { | |
socket.send('Hello, Html5'); | |
}; | |
// Log any data pushed from the server | |
socket.onmessage = function(event) { | |
console.log(event.data); | |
} | |
// Once the socket connection is closed ... log closed to the console. | |
socket.onclose = function(event) { | |
console.log('closed'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment