Skip to content

Instantly share code, notes, and snippets.

@sean3z
Created March 18, 2018 02:43
Show Gist options
  • Save sean3z/dc451a5c7a2ef1f19457dcf0a0a7ee1f to your computer and use it in GitHub Desktop.
Save sean3z/dc451a5c7a2ef1f19457dcf0a0a7ee1f to your computer and use it in GitHub Desktop.
Websocket example (Native websocket)
<div id="content"></div>
<script type="text/javascript">
var content = document.getElementById('content');
var socket = new WebSocket('ws://localhost:1337');
socket.onopen = function () {
socket.send('hello from the client');
};
socket.onmessage = function (message) {
content.innerHTML += message.data +'<br />';
};
socket.onerror = function (error) {
console.log('WebSocket error: ' + error);
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment