Skip to content

Instantly share code, notes, and snippets.

@cpilsworth
Last active August 29, 2015 14:19
Show Gist options
  • Save cpilsworth/9ac8574c6aa05ffa5ed6 to your computer and use it in GitHub Desktop.
Save cpilsworth/9ac8574c6aa05ffa5ed6 to your computer and use it in GitHub Desktop.
Displays the responses from a web socket
<!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