Index: web/testclient/README =================================================================== --- web/testclient/README (nonexistent) +++ web/testclient/README (revision 4931) @@ -0,0 +1,20 @@ +testclient +========== + +Client side files for testing a websocket server in a compatible browser. +These files should be served by the tested webserver. + +The client is logging to the javascript console, so it's advisable to open it +by pressing Ctrl-Shift-C in the browser. + + +The echo server socket +---------------------- + +The client assumes that there is a websocket server listening at the `/echo` +url that accepts free text messages. The client attempts to open the socket +on startup. + +The user can send a message to the echo socket by typing it into the 'message' +text box and clicking the 'send' button. Messages received from the echo +socket are displayed in the 'response' text box. Index: web/testclient/index.html =================================================================== --- web/testclient/index.html (nonexistent) +++ web/testclient/index.html (revision 4931) @@ -0,0 +1,18 @@ + + + + + Test client for websocket + + +

Websocket test

+ Press Shift-Ctrl-C to open the debug console. +
+

say something to the echo

+ +
+ +
+ + + \ No newline at end of file Index: web/testclient/scripts.js =================================================================== --- web/testclient/scripts.js (nonexistent) +++ web/testclient/scripts.js (revision 4931) @@ -0,0 +1,43 @@ +var echoText = document.getElementById("echo-text"); +var echoResponse = document.getElementById("echo-response"); + + +function echoSend() { + console.log(echoText.value); + echoSocket.send(echoText.value); + echoText.value = ""; +} + + +function getWebSocketUrl(relpath) { + var loc = window.location, url; + if (loc.protocol === "https:") { + url = "wss:"; + } else { + url = "ws:"; + } + url += "//" + loc.host + "/" + relpath; + return url; +} + + +var echoSocket = new WebSocket(getWebSocketUrl("echo"), "remote-hid-protocol"); + +echoSocket.onopen = function (event) { + console.log("echo socket is open at", echoSocket.url); +}; + +echoSocket.onclose = function (event) { + console.log("echo socket is closed"); +}; + +echoSocket.onerror = function (event) { + console.log("echo socket error", event); +}; + +echoSocket.onmessage = function (event) { + console.log(event.data); + echoResponse.value = event.data; +}; + +