Skip to content

Instantly share code, notes, and snippets.

@rogerwelin
Created March 13, 2018 22:42
Show Gist options
  • Save rogerwelin/6b09cfa5c485428a4be0b36ed8da4c4c to your computer and use it in GitHub Desktop.
Save rogerwelin/6b09cfa5c485428a4be0b36ed8da4c4c to your computer and use it in GitHub Desktop.
websocket html
<html>
<head>
</head>
<body>
<h1>Long/lat:</h1>
<!-- 1 -->
<div id="long"></div>
<div id="lat"></div>
<script type="text/javascript">
var long = document.getElementById("long");
var lat = document.getElementById("lat");
// 2
var exampleSocket = new WebSocket("ws://localhost:8844/ws")
// 3
var update = function(){
exampleSocket.onmessage = function (event) {
var longlatArr = event.data.split(" ");
long.textContent = longlatArr[1].toString();
lat.textContent = longlatArr[0].toString();
}
};
window.setTimeout(update);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment