rf-web/vendor/bundle/gems/em-websocket-0.5.1/examples/test.html

30 lines
927 B
HTML
Raw Normal View History

2019-10-21 08:18:17 +00:00
<html>
<head>
<script>
function init() {
function debug(string) {
var element = document.getElementById("debug");
var p = document.createElement("p");
p.appendChild(document.createTextNode(string));
element.appendChild(p);
}
var Socket = "MozWebSocket" in window ? MozWebSocket : WebSocket;
var ws = new Socket("ws://localhost:8080/foo/bar?hello=world");
ws.onmessage = function(evt) { debug("Received: " + evt.data); };
ws.onclose = function(event) {
debug("Closed - code: " + event.code + ", reason: " + event.reason + ", wasClean: " + event.wasClean);
};
ws.onopen = function() {
debug("connected...");
ws.send("hello server");
ws.send("hello again");
};
};
</script>
</head>
<body onload="init();">
<div id="debug"></div>
</body>
</html>