Crow/examples/websocket/templates/ws.html
The-EDev fd6de9bc05
Added functionality to close websocket connections before the app is
terminated.
This is incomplete and needs more work.
2021-11-06 06:06:18 +03:00

43 lines
818 B
HTML

<!doctype html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
</head>
<body>
<input id="msg" type="text"></input>
<button id="send">
Send
</button><BR>
<textarea id="log" cols=100 rows=50>
</textarea>
<script>
var sock = new WebSocket("ws://{{servername}}:40080/ws");
sock.onopen = ()=>{
console.log('open')
}
sock.onerror = (e)=>{
console.log('error',e)
}
sock.onclose = (e)=>{
console.log('close', e)
}
sock.onmessage = (e)=>{
$("#log").val(
e.data +"\n" + $("#log").val());
}
$("#msg").keypress(function(e){
if (e.which == 13)
{
sock.send($("#msg").val());
$("#msg").val("");
}
});
$("#send").click(()=>{
sock.send($("#msg").val());
$("#msg").val("");
});
</script>
</body>
</html>