Created
August 7, 2013 22:14
-
-
Save pk11/6179306 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
<html> | |
<body> | |
<!-- Send text to websocket --> | |
<input id="userInput" type="text"> | |
<button onclick="ws.send(document.getElementById('userInput').value)">Send</button> | |
<h1>Websockets demo</h1> | |
<!-- Results --> | |
<div id="message"></div> | |
<script> | |
function showMessage(text) { | |
document.getElementById('message').innerHTML = text; | |
} | |
var ws = new WebSocket('ws://' + document.location.host + '/websockets'); | |
showMessage('Connecting...'); | |
ws.onopen = function() { showMessage('Connected!'); }; | |
ws.onclose = function() { showMessage('Lost connection'); }; | |
ws.onmessage = function(msg) { showMessage(msg.data); }; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment