mirror of
https://github.com/KevinMidboe/delugeClient.git
synced 2025-10-28 19:40:12 +00:00
45 lines
1.5 KiB
HTML
45 lines
1.5 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>WebSocket demo</title>
|
|
</head>
|
|
<body>
|
|
<input placeholder="Your name here"></input>
|
|
<button onclick="sendMessage()">Send message</button>
|
|
<br />
|
|
<span>Message from server: </span>
|
|
<span id="response"></span>
|
|
|
|
<script>
|
|
function sendMessage() {
|
|
let ws = new WebSocket("ws://localhost:8765/")
|
|
let test = 'hello'
|
|
ws.onopen = function (event) {
|
|
ws.send(document.getElementsByTagName('input')[0].value);
|
|
}
|
|
ws.onerror = function() {
|
|
console.error("error");
|
|
}
|
|
ws.onclose = function() {
|
|
console.log("closed");
|
|
}
|
|
ws.onmessage = function (event) {
|
|
let server_resp = event.data;
|
|
document.getElementById('response').textContent= server_resp;
|
|
}
|
|
}
|
|
</script>
|
|
<script>
|
|
let ws_time = new WebSocket("ws://localhost:5678/"),
|
|
messages = document.createElement('ul');
|
|
ws_time.onmessage = function (event) {
|
|
let messages = document.getElementsByTagName('ul')[0],
|
|
message = document.createElement('li'),
|
|
content = document.createTextNode(event.data);
|
|
message.appendChild(content);
|
|
messages.appendChild(message);
|
|
};
|
|
document.body.appendChild(messages);
|
|
</script>
|
|
</body>
|
|
</html> |