-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.html
50 lines (46 loc) · 1.02 KB
/
index.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
46
47
48
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
var ws = new Object;
function send()
{
ws.send("hello world!");
console.log('Message sent');
}
function open()
{
if (!("WebSocket" in window)) {
alert("This browser does not support WebSockets");
return;
}
/* @todo: Change to your own server IP address */
ws = new WebSocket("ws://127.0.0.1:8080");
ws.onopen = function() {
console.log('Connected');
};
ws.onmessage = function (evt)
{
var received_msg = evt.data;
console.log("Received: " + received_msg);
var txt = document.createTextNode("
Simon says: " + received_msg
);
document.getElementById('msgs').appendChild(txt);
};
ws.onclose = function()
{
console.log('Connection closed');
};
}
</script>
</head>
<body>
<div id="sse">
<a href="javascript:open()">Open websocket connection</a><br/>
<a href="javascript:send()">Send Message</a>
</div>
<div id="msgs">
</div>
</body>
</html>