Last active
August 29, 2015 14:19
-
-
Save cpilsworth/9ac8574c6aa05ffa5ed6 to your computer and use it in GitHub Desktop.
Displays the responses from a web socket
This file contains hidden or 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> | |
<body> | |
<pre id="server_events"></pre> | |
<script> | |
var socket = new WebSocket("ws://" + window.location.hostname + ":8888/"); | |
var code = document.getElementById("server_events"); | |
var msgs = 0; | |
socket.onopen = function(){ | |
console.log("Socket has been opened!"); | |
} | |
socket.onmessage = function(msg){ | |
msgs++; | |
code.appendChild(document.createTextNode(msg.data+ '\n')); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment