mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-30 00:00:16 +01:00
50 lines
1.1 KiB
HTML
50 lines
1.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset=utf-8 />
|
|
<title>Minimal Websocket message sender</title>
|
|
</head>
|
|
|
|
<body>
|
|
<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 {
|
|
// alert('<p class="event">Socket Status: '+socket.readyState);
|
|
|
|
socket.onopen = function(){
|
|
// alert('<p class="event">Socket Status: '+socket.readyState+' (open)');
|
|
}
|
|
|
|
socket.onmessage = got_packet;
|
|
|
|
socket.onclose = function(){
|
|
alert('<p class="event">Socket Status: (Closed)');
|
|
}
|
|
} catch(exception){
|
|
alert('<p>Error'+exception);
|
|
}
|
|
|
|
function got_packet(msg){
|
|
|
|
// alert('got packet' + msg.data);
|
|
document.body.textContent = msg.data + "\n";
|
|
|
|
}
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|