diff options
author | Paul Hawke <paul.hawke@gmail.com> | 2014-04-23 23:08:57 -0500 |
---|---|---|
committer | Paul Hawke <paul.hawke@gmail.com> | 2014-04-23 23:08:57 -0500 |
commit | c6c080a6f4377fb18fc869111714e9514c36331a (patch) | |
tree | 1ac1f8ad3486e39bd2591bd5d603dcd09de8f0e9 /websocket/src/test/resources/echo-test.html | |
parent | 6d3737c76afdb1c991bf8d96e3dd2cc622435f09 (diff) | |
download | nanohttpd-c6c080a6f4377fb18fc869111714e9514c36331a.tar.gz |
websockets: final polish before release. Tested on IE, Chrome and Firefox
Diffstat (limited to 'websocket/src/test/resources/echo-test.html')
-rw-r--r-- | websocket/src/test/resources/echo-test.html | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/websocket/src/test/resources/echo-test.html b/websocket/src/test/resources/echo-test.html new file mode 100644 index 0000000..4b60b80 --- /dev/null +++ b/websocket/src/test/resources/echo-test.html @@ -0,0 +1,58 @@ +<html> +<head> + <meta charset="utf-8"/> + <title>WebSocket Test</title> + <script language="javascript" type="text/javascript"> + var wsUri = "ws://localhost:9090/"; + var output; + function init() { + output = document.getElementById("output"); + testWebSocket(); + } + function testWebSocket() { + websocket = new WebSocket(wsUri); + websocket.onopen = function (evt) { + onOpen(evt) + }; + websocket.onclose = function (evt) { + onClose(evt) + }; + websocket.onmessage = function (evt) { + onMessage(evt) + }; + websocket.onerror = function (evt) { + onError(evt) + }; + } + function onOpen(evt) { + writeToScreen("CONNECTED"); + doSend("WebSocket rocks"); + } + function onClose(evt) { + writeToScreen("DISCONNECTED"); + } + function onMessage(evt) { + writeToScreen('<span style="color: blue;">RESPONSE: ' + evt.data + '</span>'); + websocket.close(); + } + function onError(evt) { + writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data); + } + function doSend(message) { + writeToScreen("SENT: " + message); + websocket.send(message); + } + function writeToScreen(message) { + var pre = document.createElement("p"); + pre.style.wordWrap = "break-word"; + pre.innerHTML = message; + output.appendChild(pre); + } + window.addEventListener("load", init, false); </script> +</head> +<body> +<h2>WebSocket Test</h2> + +<div id="output"></div> +</body> +</html>
\ No newline at end of file |