-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
511 lines (425 loc) · 15.8 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<meta name="author" content="itspoma, Roman Rodomansky" />
<meta name="keywords" content="" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.2.0/css/reveal.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.2.0/css/theme/simple.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.2.0/lib/css/zenburn.min.css" />
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.2.0/lib/js/html5shiv.min.js"></script>
<![endif]-->
<style>
.slides img {
border: none !important;
box-shadow: none !important;
}
</style>
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<h2>WebSockets (vs HTTP)</h2>
<img src="http://westchesterhomeowner.com/wp-content/uploads/2012/05/outlet.jpg" width="30%" />
<br/>
<small>Meteor Girls Lviv, 12.03.2016</small>
</section>
<section>
<section>
<h2>The problem areas</h2>
<p>
<ul>
<li class="fragment">real-time (event-driven) apps
<li class="fragment">social & online games
<li class="fragment">collaborative platforms
<li class="fragment">financial applications
<li class="fragment">social feeds
<li class="fragment">chats
<li class="fragment">etc
</ul>
</p>
</section>
</section>
<section>
<section>
<h2>Internet Layers</h2>
<p>
<img src="http://new.tinygrab.com/7020c0e8b0b76ee5e74eb5313829e350e8d9fa411e.png" width="70%" />
</p>
</section>
<section>
<h2>TCP/IP Model</h2>
<p>
<img src="https://i-technet.sec.s-msft.com/dynimg/IC197700.gif" width="80%" />
</p>
</section>
</section>
<section>
<section>
<h2>Hyper Text Transfer Protocol</h2>
</section>
<section>
<h2>HTTP model</h2>
<p>
<img src="http://www.stream-hub.com/images/traditionalhttp.png" width="100%" />
<br/>
The request/response model
</p>
</section>
<section>
<h2>HTTP page loading</h2>
<p>
<img src="http://new.tinygrab.com/7020c0e8b03520f597e7e1f228c5b8dc1ec74667b6.png" width="30%" />
</p>
</section>
<section>
<h2>HTTP cons</h2>
<p>
<ul>
<li>new TCP connection
<li>half-duplex (can only receive or send)
<li>limitations
</ul>
</p>
</section>
<section>
<h2>HTTP "Hello World"</h2>
<p>
<pre><code class="http" data-trim>GET /7020c0e8b09f4314ceee7c0ebccaff3fe956da1820.png HTTP/1.1
Host: new.tinygrab.com
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Accept: image/webp,image/*,*/*;q=0.8
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8,ru;q=0.6,uk;q=0.4
Cookie: __utma=80076562.1; __utmc=80076562; __utmz=80076562
</code></pre>
<br/>
Total 456 chars. Req/res overhead?
</p>
</section>
<section>
<h2>HTTP Polling Architecture</h2>
<p>
<img src="http://new.tinygrab.com/7020c0e8b0dfc21f69077c4d967a20e3dce9f6a45d.png" width="50%" />
<br/>
Request every n seconds
</p>
</section>
<section>
<h2>HTTP Polling (js)</h2>
<p>
<pre><code class="js" data-trim>
setInterval(function() {
$.ajax({
url: '/server',
dataType: 'json',
success: function () { ... }
})
}, 30000);
</code></pre>
<br/>
Request every 30 seconds the "/server" endpoint
</p>
</section>
<section>
<h2>HTTP Long-Polling Architecture</h2>
<p>
<img src="http://new.tinygrab.com/7020c0e8b0eb1aa0edba78da6a6f609c0fedb6bfba.png" width="50%" />
<br/>
Request every n seconds \w wait-delay
</p>
</section>
<section>
<h2>HTTP Streaming</h2>
<p>
<img src="http://new.tinygrab.com/7020c0e8b0ff64238473a43ed8b254e03316069180.png" width="50%" />
</p>
</section>
<section data-background="https://lh3.googleusercontent.com/5ZzyJxWlvA7DkiSIZNceN4gt3eRSiPf1d-1sge6ph_LYLxepZlZ70JEPjemOM1UYIIp-jyDugbYwWSHPyfKoTdi6r68kI-tDn1ScgmrtZzz7Dz-SdKQILNTN3TV2K8rYJPG0Cxc" data-background-size="100%">
<h2> </h2>
</section>
</section>
<section>
<section>
<h2>WebSockets</h2>
<p>
<img src="https://lizbedor.files.wordpress.com/2015/05/200-7.gif" width="60%" />
</p>
</section>
<section>
<img src="http://new.tinygrab.com/7020c0e8b00df2b4875e2cffb9607dffb6f7523ab6.png" width="100%" />
</section>
<section>
<img src="http://new.tinygrab.com/7020c0e8b05eb769241d9afe8967c46f3910c67971.png" width="100%" />
</section>
<section>
<h2>WebSockets Pros</h2>
<p>
<ul>
<li>B-directional
<li>full-duplex
<li>single TCP connection
</ul>
<br/>
<img src="https://lizbedor.files.wordpress.com/2015/05/200-8.gif" width="50%" />
</p>
</section>
<section>
<h2>WebSockets what is it?</h2>
<p>
a channel over a single TCP connection
<br/>
ws://
</p>
</section>
<section>
<h2>WebSockets how they works?</h2>
<p>
upgrade http to websocket<br/>
send data frames in both directions<br/>
end the connection
</p>
</section>
<section data-transition="convex">
<h2>WebSockets how they works?</h2>
<p>
<img src="http://new.tinygrab.com/7020c0e8b09f4314ceee7c0ebccaff3fe956da1820.png" />
</p>
</section>
<section data-transition="fade">
<h2>WebSockets how they works?</h2>
<p>
<img src="http://new.tinygrab.com/7020c0e8b0b509b03ec2043971d9af46fca141b3c4.png" width="60%" />
<br/>
switching the HTTP protocol to WebSocket
</p>
</section>
<section data-transition="fade">
<h2>WebSockets how they works?</h2>
<p>
<img src="http://new.tinygrab.com/7020c0e8b0f77cb3e6f160f384f37ada762537528f.png" width="60%" />
<br/>
each of client & server becomes as peer
</p>
</section>
<section data-transition="fade">
<h2>WebSockets how they works?</h2>
<p>
<img src="http://new.tinygrab.com/7020c0e8b041a03b9936dabc6b4b3b50472c10287e.png" width="60%" />
</p>
</section>
<section data-transition="fade">
<h2>WebSockets how they works?</h2>
<p>
<img src="http://new.tinygrab.com/7020c0e8b0e344b2b3ce1ec8796c413525fbe5efa0.png" width="60%" />
</p>
</section>
<section data-transition="fade">
<h2>WebSockets how they works?</h2>
<p>
<img src="http://new.tinygrab.com/7020c0e8b037335709ae182b07210a601079e7aa2a.png" width="60%" />
</p>
</section>
<section data-transition="fade">
<h2>WebSockets how they works?</h2>
<p>
<img src="http://new.tinygrab.com/7020c0e8b000d4b19a168dfb7042c11e762bf2ffd2.png" width="60%" />
</p>
</section>
<section data-transition="fade">
<h2>WebSockets how they works?</h2>
<p>
<img src="http://new.tinygrab.com/7020c0e8b0215a473c44d06b223e14879b3ac96d7c.png" width="60%" />
</p>
</section>
<section data-transition="fade">
<h2>WebSockets how they works?</h2>
<p>
<img src="http://new.tinygrab.com/7020c0e8b03e8cfc063472c8f27d2a3976ddac9d39.png" width="60%" />
</p>
</section>
<section data-transition="fade">
<h2>WebSockets how they works?</h2>
<p>
<img src="http://new.tinygrab.com/7020c0e8b05cf9c7a2c1089178f13f560ded10d925.png" width="60%" />
</p>
</section>
<section data-transition="fade">
<h2>WebSockets how they works?</h2>
<p>
<img src="http://new.tinygrab.com/7020c0e8b0f84639dc471e7acb660a5410c09dc51c.png" width="60%" />
</p>
</section>
<section data-transition="fade">
<h2>WebSockets how they works?</h2>
<p>
<img src="http://new.tinygrab.com/7020c0e8b0285610fee431081e11f52b18c1cc7244.png" width="60%" />
</p>
</section>
<section>
<h2>WebSockets "Hello World"</h2>
<p>
only 2 bytes of overhead<br/>
no latency for creation new TCP connection<br/>
no polling overhead (will send message when it needed)<br/>
<br/>
<img src="https://lizbedor.files.wordpress.com/2015/05/ioa8msm1.gif" width="60%" />
</p>
</section>
<section data-transition="fade">
<h2>WebSockets in browsers</h2>
<p>
<img src="http://new.tinygrab.com/7020c0e8b001680ae4b0d30a038a6a65c23740db47.png" width="100%" />
<br/>
caniuse.com 89.42%
</p>
</section>
</section>
<section>
<section>
<h2>WebSockets example (js)</h2>
<p>
<pre><code class="js" data-trim>
var ws = new WebSocket('ws://echo.websocket.org');
ws.onopen = function() { ws.send('hi'); }
ws.onmessage = function(event) { console.log('message %s', event.data) }
ws.onclose = function(event) { console.log('closed', event.code) }
</code></pre>
</p>
</section>
<section>
<h2>WebSockets example (Docker)</h2>
<p>
Dockerfile:
<pre><code class="js" data-trim>
FROM centos:6
MAINTAINER itspoma <itspoma@gmail.com>
RUN yum clean all \
&& yum install -y git curl wget mc
RUN curl --silent --location https://rpm.nodesource.com/setup | bash - \
&& yum install -y nodejs \
&& npm install -g npm@latest \
&& npm install -g inherits
RUN cd /tmp/ && npm install ws \
&& wget -O /tmp/server.js http://pastebin.com/raw/cUGe4Bgm
</code></pre>
</p>
</section>
<section>
<h2>WebSockets example (run)</h2>
<p>
Shell instructions:
<pre><code class="shell" data-trim>
$ wget -O Dockerfile http://pastebin.com/raw/0Xn5uZxc
$ docker rm -f websocket-container
$ docker rmi -f websocket-image
$ docker build -t websocket-image .
$ docker run --name=websocket-container -p 4871:8080 -tid websocket-image
$ docker exec -ti websocket-container bash
vm$ node /tmp/server.js
vm$ nohup node /tmp/server.js >/dev/null 2>&1 &
</code></pre>
</p>
</section>
<section>
<h2>WebSockets example (server.js)</h2>
<p>
<pre><code class="js" data-trim>
var WebSocketServer = require('ws').Server
, wss = new WebSocketServer({ port: 8080 });
wss.broadcast = function (data) {
wss.clients.forEach(function (client) {
client.send(data);
});
};
wss.on('connection', function (ws) {
console.log('new connection');
ws.on('message', function (message) {
console.log('received: %s', message);
wss.broadcast(message);
});
ws.send('something');
});
</code></pre>
<small>http://pastebin.com/raw/cUGe4Bgm</small>
</p>
</section>
<section>
<h2>WebSockets example (client.js)</h2>
<p>
<pre><code class="js" data-trim>
var ws = new WebSocket('ws://185.69.152.203:4871');
ws.onopen = function() { ws.send('hi'); }
ws.onmessage = function(event) { console.log('message %s', event.data) }
ws.onclose = function(event) { console.log('closed', event.code) }
ws.send('welcome');
</code></pre>
<small><a href="http://jsfiddle.net/7hvph2ob/4/" target="_blank">http://jsfiddle.net/7hvph2ob/4/</a></small>
</p>
</section>
</section>
<section>
<section>
<h2>WebSockets vs HTTP</h2>
<p>
<img src="http://orm-chimera-prod.s3.amazonaws.com/1230000000545/images/hpbn_1702.png" />
</p>
</section>
</section>
<section>
<section>
<h2>WebSockets in Meteor.js</h2>
<p>
websocket-based DDP (Distributed Data Protocol)
<br/>
<br/>
to fetch structured data from a server,<br/>
deliver live updates as data changes,<br/>
and for remote procedure call
</p>
</section>
<section>
<h2>Meteor.js DDP</h2>
<p>
<img src="https://camo.githubusercontent.com/5571989633efd5ad46471cd41a4ca182e7c6657e/68747470733a2f2f692e636c6f756475702e636f6d2f4973555658554f7370612e706e67" />
</p>
</section>
</section>
<section data-background="https://lizbedor.files.wordpress.com/2015/05/thanks.gif" data-background-size="60%">
<h2 style="color:white; margin-top:-35%;"><b>Questions?</b></h2>
</section>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.2.0/lib/js/head.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.2.0/js/reveal.min.js"></script>
<script>
(function() {
var CDN = 'https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.2.0';
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
transition: 'zoom',
dependencies: [
{ src: CDN + '/lib/js/classList.min.js', condition: function() { return !document.body.classList; } },
{ src: CDN + '/plugin/markdown/marked.min.js', condition: function() { return !!document.querySelector('[data-markdown]'); } },
{ src: CDN + '/plugin/markdown/markdown.min.js', condition: function() { return !!document.querySelector('[data-markdown]'); } },
{ src: CDN + '/plugin/highlight/highlight.min.js', async: true, condition: function() { return !!document.querySelector('pre code'); }, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: CDN + '/plugin/zoom-js/zoom.min.js', async: true },
{ src: CDN + '/plugin/notes/notes.min.js', async: true }
]
});
})();
</script>
</body>
</html>