forked from heroku-examples/node-ws-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
76 lines (62 loc) · 1.75 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<html>
<head>
<style>
body {
font-family: "Helvetica Neue", helvetica, arial;
padding: 15px;
}
ul {
list-style: none;
margin: 0;
padding: 0;
}
ul li {
line-height: 1.4;
}
</style>
<script>
var host = location.origin.replace(/^http/, 'ws')
var websocket = new WebSocket(host);
console.log(websocket);
websocket.onopen = function() {
console.log('hello')
websocket.send("Hello"); // Sends a message.
};
websocket.onmessage = function (evt)
{
var received_msg = evt.data;
// alert("Message is received...");
console.log(received_msg);
};
var test = function() {
console.log('test');
websocket.send('I am the client and I\'m listening!');
}
// websocket.onmessage = function(str) {
// console.log("Someone sent: ", str);
// };
// // Tell the server this is client 1 (swap for client 2 of course)
// websocket.send(JSON.stringify({
// id: "client1"
// }));
// // Tell the server we want to send something to the other client
// websocket.send(JSON.stringify({
// to: "client2",
// data: "foo"
// }));
// console.log(websocket);
// websocket.on('open', function open() {
// var array = new Float32Array(5);
// for (var i = 0; i < array.length; ++i) {
// array[i] = i / 2;
// }
// websocket.send(array, { binary: true, mask: true });
// });
</script>
</head>
<body>
<input type="text" id="msg" value="test">
<input type="button" id="send" value="send" onclick="test()">
<ul id="pings"></ul>
</body>
</html>