Created
January 20, 2013 22:09
-
-
Save sadah/4582144 to your computer and use it in GitHub Desktop.
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
| <!doctype html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Document</title> | |
| <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script> | |
| <script> | |
| $(function(){ | |
| var host = "ws://localhost:8888/"; | |
| var socket = new WebSocket(host); | |
| console.log(socket.readyState); | |
| socket.onopen = function(){ | |
| console.log(socket.readyState); | |
| } | |
| socket.onmessage = function(message){ | |
| console.log(socket.readyState + " " + message.data); | |
| } | |
| socket.onclose = function(){ | |
| console.log(socket.readyState); | |
| } | |
| $(window).unload(function() { | |
| socket.onclose(); | |
| console.log(socket.readyState); | |
| }) | |
| $("#sendBtn").on("click",function(){ | |
| message = $("#message").val() | |
| socket.send(message); | |
| }); | |
| }) | |
| </script> | |
| </head> | |
| <body> | |
| <h1>Hello World!</h1> | |
| <input type="text" id="message" /><button id="sendBtn">send</button> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment