-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.html
More file actions
62 lines (60 loc) · 2.04 KB
/
client.html
File metadata and controls
62 lines (60 loc) · 2.04 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE html>
<html>
<head>
<title>WebSocket demo</title>
<script>
function wsstatus(){
if ("WebSocket" in window)
{
document.getElementById("m").innerHTML=('WebSockets supported!');
}
}
function printstatus(msg)
{
document.getElementById("m").innerHTML += '<br />' + msg;
}
function clearstatus()
{
document.getElementById("m").innerHTML = '';
}
function WebSocketShell()
{
if ("WebSocket" in window)
{
var server = "localhost:5678/hello/world"
var ws = new WebSocket("ws://" + server);
clearstatus();
printstatus ('Connecting to ' + server);
ws.onopen = function()
{
printstatus ('Connected!')
ws.send(document.getElementById('in').value);
printstatus('Command sent.. Waiting for server..')
};
ws.onmessage = function (evt)
{
var received_msg = evt.data;
printstatus(received_msg);
};
ws.onclose = function(a)
{
clearstatus();
printstatus('Connection could not be estabilished. Closing websocket.');
};
}
else
{
printstatus("WebSocket NOT supported by your Browser!");
}
}
</script>
</head>
<body>
<div id="sse"><p>
<b>Enter command: </b><input type="text" id="in" name="in" />
<button onclick="WebSocketShell()">Execute!</button></p>
</div>
<p><b>Status: </b></p>
<pre><div id="m"></div></pre>
</body>
</html>