Skip to content

Instantly share code, notes, and snippets.

@AndyNovo
Created December 4, 2017 00:17
Show Gist options
  • Save AndyNovo/2e5a58478b2b1640710170fdba1ac617 to your computer and use it in GitHub Desktop.
Save AndyNovo/2e5a58478b2b1640710170fdba1ac617 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>WebSocket Test</title>
</head>
<body>
<ul id="msgs">
</ul>
<script>
var ws;
window.onload=function(){
ws=new WebSocket("wss://SPACENAME-USERNAME.c9users.io:8081");
ws.onmessage=function(evt){ document.querySelector("#msgs").innerHTML += `<li>${evt.data}</li>`;};
ws.onopen=function(evt){
ws.send("Hello");
}
}
window.onclose=function(){
ws.close();
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment