tesses.webserver.websocket/Tesses.WebServer.WebSocketS.../www/index.html

30 lines
821 B
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WebSocket test</title>
</head>
<body>
<input type="text" name="field" id="field">
<button onclick="send()">Send</button>
<div id="msg">
</div>
<script>
function send()
{
const txt = document.getElementById('field');
ws.send(txt.value);
txt.value="";
}
const ws = new WebSocket(`ws://${window.location.host}/api/socket`);
ws.addEventListener('message', (event) => {
const data = document.getElementById('msg');
data.innerText += event.data + '\n';
});
</script>
</body>
</html>