Created
June 10, 2013 07:23
-
-
Save ankurtrapasiya/5747066 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 http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | |
<title>Web Socket Example</title> | |
<script> | |
var socket = new WebSocket( | |
"ws://localhost:8080/WebSocketExample/SocketServlet"); | |
socket.onopen = function() { | |
alert("opened a socket"); | |
}; | |
socket.onmessage = function(message) { | |
document.getElementById("chatlog").textContent += message.data + "\n"; | |
}; | |
function postToServer() { | |
socket.send(document.getElementById("msg").value); | |
document.getElementById("msg").value = ""; | |
} | |
function closeConnect() { | |
socket.close(); | |
} | |
</script> | |
</head> | |
<body> | |
<textarea id="chatlog" readonly></textarea> | |
<br /> | |
<input id="msg" type="text" /> | |
<button type="submit" id="sendButton" onClick="postToServer()">Send!</button> | |
<button type="submit" id="sendButton" onClick="closeConnect()">End</button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment