Created
October 30, 2014 17:50
-
-
Save ionox0/caf78a74119e5d2ba876 to your computer and use it in GitHub Desktop.
Websockets implementation http://www.elabs.se/blog/66-using-websockets-in-native-ios-and-android-apps
This file contains hidden or 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
$(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