-
Notifications
You must be signed in to change notification settings - Fork 24
/
ws.html
50 lines (47 loc) · 1.51 KB
/
ws.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
<!doctype html>
<!--
WebSocket example - frontend - from:
https://github.com/rsp/node-websocket-vs-socket.io
Copyright (c) 2015, 2016 Rafał Pocztarski
Released under MIT License (Expat) - see:
https://github.com/rsp/node-websocket-vs-socket.io/blob/master/LICENSE.md
-->
<html lang=en>
<head>
<meta charset=utf-8>
<meta name=viewport content="width=device-width, initial-scale=1">
<title>websocket example - node-websocket-vs-socket.io</title>
<style>
h1 { font-family: helvetica, sans-serif; margin: 0; }
h1+p { margin: 0; }
</style>
</head>
<body>
<h1>websocket example</h1>
<p>
From node-websocket-vs-socket.io by Rafał Pocztarski
<br><a href="https://github.com/rsp/node-websocket-vs-socket.io">https://github.com/rsp/node-websocket-vs-socket.io</a>
<br>Comparing WebSocket vs. Socket.IO on Node.js with Express.js
</p>
<p>
Open developer tools with Shift+Ctrl+I,
select Network and reload the page.
<br>This is the websocket example.
See also the <a href="http://localhost:3002/">socket.io example</a>.
</p>
<ol id=l></ol>
<script>
var l = document.getElementById('l');
var log = function (m) {
var i = document.createElement('li');
i.innerText = new Date().toISOString()+' '+m;
l.appendChild(i);
}
log('opening websocket connection');
var s = new WebSocket('ws://'+window.location.host+'/');
s.addEventListener('error', function (m) { log("error"); });
s.addEventListener('open', function (m) { log("websocket connection open"); });
s.addEventListener('message', function (m) { log(m.data); });
</script>
</body>
</html>