is this thing listening?

This commit is contained in:
2024-01-17 22:06:13 -05:00
commit 8809203953
5 changed files with 813 additions and 0 deletions

49
ws_test.html Normal file
View File

@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html>
<head>
<style>
body{
background:#1d2021;
color:#bdae93;
}
.page{
height:500px;
width:400px;
overflow-y:scroll;
border:1px solid #a89984;
}
</style>
</head>
<body>
<h1>Messages:</h1>
<div class="page"></div>
<input type="text" placeholder="Enter message" id="area" autofocus>
<script>
var page = document.getElementsByClassName("page")[0]
var host = 'ws://localhost:8080/';
var socket = new WebSocket("ws://localhost:8080");
socket.onmessage = function(e){
page.innerHTML += "<br>" + e.data;
};
socket.onerror = function(e){
page.innerHTML += "<h3>Connection error</h3>";
}
var area = document.getElementById("area");
area.onkeyup = function(e){
if(e.key == "Enter"){
socket.send(area.value);
area.value = "";
area.focus();
}
}
</script>
</body>
</html>