Created
November 21, 2015 14:28
-
-
Save mneko22/30de726268aecbf4b958 to your computer and use it in GitHub Desktop.
メッセが送信されたら"北海道はでっかいどー"と返す奴
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 charset="UTF-8"> | |
<title>北海道って意外と小さいんじゃない?</title> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
WebSocketDemo = {}; | |
(function(d) { | |
function $(query) { | |
return document.querySelector(query); | |
} | |
function printMessage(msg) { | |
$("#msgbox").innerHTML += "<div>" + msg + "</div>"; | |
} | |
d.connect = function() { | |
var ws = new WebSocket("ws://localhost:8080/Test/websocket"); | |
ws.onmessage = function(event) { | |
printMessage("Server : " + event.data); | |
}; | |
d.webSocket = ws; | |
$("#connect").disabled = true; | |
$("#send").disabled = false; | |
}; | |
d.send = function() { | |
var msg = $("#msg").value; | |
d.webSocket.send(msg); | |
printMessage("Client : " + msg); | |
}; | |
}) (WebSocketDemo); | |
</script> | |
<form action="javascript:void(0);"> | |
<input type="text" id="msg" size="20"> | |
<input type="button" id="connect" value="Connect" onclick="WebSocketDemo.connect();"> | |
<input type="button" id="send" value="Send" onclick="WebSocketDemo.send();" disabled> | |
</form> | |
<div id="msgbox" style="border-style: solid;width: 500px;height: 400px"></div> | |
</body> | |
</html> |
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
package websocket; | |
import javax.websocket.*; | |
import javax.websocket.server.ServerEndpoint; | |
@ServerEndpoint(value = "/websocket") | |
public class WebsocketDemo { | |
@OnMessage | |
public String onMessage(String text){ | |
return "北海道はでっかいどーーーー"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment