Created
March 18, 2018 02:43
-
-
Save sean3z/dc451a5c7a2ef1f19457dcf0a0a7ee1f to your computer and use it in GitHub Desktop.
Websocket example (Native websocket)
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
<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