Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sadah
Created January 31, 2013 11:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sadah/4682199 to your computer and use it in GitHub Desktop.
Save sadah/4682199 to your computer and use it in GitHub Desktop.
Java♡HTML5 Night でライブコーディングしたクライアントサイドのWebSocketのサンプルコード。 ライブコーディングなので、いろいろ適当ですが。
<!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