Created
January 31, 2013 11:15
-
-
Save sadah/4682199 to your computer and use it in GitHub Desktop.
Java♡HTML5 Night でライブコーディングしたクライアントサイドのWebSocketのサンプルコード。
ライブコーディングなので、いろいろ適当ですが。
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
<title>JSP Page</title> | |
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script> | |
<script> | |
$(function(){ | |
var host = "ws://localhost:8080/WebApplication3/echo"; | |
var socket = new WebSocket(host); | |
socket.onmessage = function(message){ | |
console.log(message.data); | |
} | |
$("#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