-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebsockets.html
45 lines (42 loc) · 988 Bytes
/
websockets.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<html>
<div>
<h1>Go websockets TODO example</h1>
<p>Available commands for todo app</p>
<p>- add [task]</p>
<p>- done [task]</p>
<input id="input" type="text" size="40" />
<button onclick="send()">Send</button>
<pre id="output"></pre>
</div>
<style>
html {
text-align: center;
font-size: 16px;
}
div {
padding: 1rem;
}
#input {
font-size: 16px;
}
p {
font-size: 16px;
}
</style>
<script>
var input = document.getElementById("input");
var output = document.getElementById("output");
var socket = new WebSocket("ws://go-websocket-teste.herokuapp.com/todo");
socket.onopen = function () {
output.innerHTML += "Status: Connected\n";
};
socket.onmessage = function (e) {
console.log(e)
output.innerHTML += "\nServer: " + e.data + "\n";
};
function send() {
socket.send(input.value);
input.value = "";
}
</script>
</html>