Skip to content

Instantly share code, notes, and snippets.

@ionox0
Created October 30, 2014 17:50
Show Gist options
  • Save ionox0/caf78a74119e5d2ba876 to your computer and use it in GitHub Desktop.
Save ionox0/caf78a74119e5d2ba876 to your computer and use it in GitHub Desktop.
$(document).ready(function() {
ws = new WebSocket("ws://" + location.hostname + ":8080/");
ws.onmessage = function(event) {
$("#messages").append("<p>" + event.data + "</p>");
};
ws.onclose = function() {
console.log("Socket closed");
};
ws.onopen = function() {
console.log("Connected");
ws.send("Hello from " + navigator.userAgent);
};
$("#new-message").bind("submit", function(event) {
event.preventDefault();
ws.send($("#message-text").val());
$("#message-text").val("");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment