Created
November 6, 2013 08:57
-
-
Save mihaisoloi/7332988 to your computer and use it in GitHub Desktop.
Testing WS functionality
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
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<script type="text/javascript"> | |
function WebSocketTest() | |
{ | |
if ("WebSocket" in window) | |
{ | |
alert("WebSocket is supported by your Browser!"); | |
// Let us open a web socket | |
//172.18.32.21:9001/stream/assets | |
//172.18.32.20:9001/datapoints/40 | |
var ws = new WebSocket("ws://172.18.32.20:9001/datapoints/40"); | |
ws.onopen = function() | |
{ | |
// Web Socket is connected, send data using send() | |
alert("Message is sent..."); | |
}; | |
ws.onmessage = function (evt) | |
{ | |
var received_msg = evt.data; | |
document.write("<div style='font-size:11px; border-bottom:1px solid'>"+received_msg+"</div>"); | |
}; | |
ws.onclose = function() | |
{ | |
// websocket is closed. | |
alert("Connection is closed..."); | |
}; | |
} | |
else | |
{ | |
// The browser doesn't support WebSocket | |
alert("WebSocket NOT supported by your Browser!"); | |
} | |
} | |
</script> | |
</head> | |
<body> | |
<div id="sse"> | |
<a href="javascript:WebSocketTest()">Run WebSocket</a> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment