Skip to content

Instantly share code, notes, and snippets.

@jessecravens
Created March 8, 2012 03:45
Show Gist options
  • Save jessecravens/1998492 to your computer and use it in GitHub Desktop.
Save jessecravens/1998492 to your computer and use it in GitHub Desktop.
Basic Web Sockets
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