mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-30 00:00:16 +01:00
63 lines
1.4 KiB
HTML
63 lines
1.4 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset=utf-8 />
|
|
<title>Minimal Websocket test app</title>
|
|
</head>
|
|
|
|
<body>
|
|
<h2>libwebsockets "dumb-increment-protocol" test applet</h2>
|
|
The incrementing number is coming from the server.
|
|
Click the button to send the server a websocket message to
|
|
reset the number.<br><br>
|
|
|
|
<table>
|
|
<tr>
|
|
<td align=center><input type=button id=offset value="Reset counter" onclick="reset();" ></td>
|
|
<td width=100 align=center><div id=number> </div></td>
|
|
<td id=statustd align=center><div id=wsstatus>Not initialized</div></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<script>
|
|
var pos = 0;
|
|
var websocket_ads;
|
|
|
|
/*
|
|
* We open the websocket encrypted if this page came on an
|
|
* https:// url itself, otherwise unencrypted
|
|
*/
|
|
|
|
if (document.URL.substring(0, 5) == "https")
|
|
websocket_ads = "wss://127.0.0.1:7681";
|
|
else
|
|
websocket_ads = "ws://127.0.0.1:7681"
|
|
|
|
var socket = new WebSocket(websocket_ads, "dumb-increment-protocol");
|
|
|
|
try {
|
|
socket.onopen = function() {
|
|
statustd.style.backgroundColor = "#40ff40";
|
|
wsstatus.textContent = " websocket connection opened ";
|
|
}
|
|
|
|
socket.onmessage =function got_packet(msg) {
|
|
number.textContent = msg.data + "\n";
|
|
}
|
|
|
|
socket.onclose = function(){
|
|
statustd.style.backgroundColor = "#ff4040";
|
|
wsstatus.textContent = " websocket connection closed ";
|
|
}
|
|
} catch(exception) {
|
|
alert('<p>Error'+exception);
|
|
}
|
|
|
|
function reset() {
|
|
socket.send("reset\n");
|
|
}
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|