Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Websockets
Search
Jonathan Wallace
February 05, 2013
Programming
140
2
Share
Websockets
Review websockets, what they are and give a simple example
Jonathan Wallace
February 05, 2013
More Decks by Jonathan Wallace
See All by Jonathan Wallace
Modern Data Literacy
jwallace
0
170
Tailoring Mentorship (with speaker notes)
jwallace
0
380
Tailoring Mentorship (only slides)
jwallace
0
470
Trusty URIs
jwallace
0
170
Navigating Your Options for Mobile App Development
jwallace
1
180
Effective Debugging - Big Nerd Ranch Tech Talk
jwallace
2
230
Effective Debugging Rubyconf
jwallace
2
370
Importance of IS in Startups
jwallace
0
110
Chef and puppet
jwallace
0
150
Other Decks in Programming
See All in Programming
Swiftのレキシカルスコープ管理
kntkymt
0
210
ADKを使って簡単にAIエージェントを作ってみよう
k1mu21
0
200
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
480
関係性から理解する"同一性"の型用語たち
pvcresin
2
630
AIエージェントの隔離技術の徹底比較
kawayu
0
460
DynamoDBには集計系のクエリがないけどなんとかしたい
musan
1
130
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
250
AIとASP.NET Coreで雑Webアプリを作った話
mayuki
0
280
プラグインで拡張される Context をtype-safe にする難しさと設計判断
kazupon
2
580
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
8
3.2k
タクシーアプリ『GO』の バックエンド開発のおける AI利活用と若者のすべて
pyama86
3
1.8k
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
3
460
Featured
See All Featured
Between Models and Reality
mayunak
4
320
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
590
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.8k
Designing for humans not robots
tammielis
254
26k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
820
For a Future-Friendly Web
brad_frost
183
10k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
The Curse of the Amulet
leimatthew05
1
13k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
530
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
390
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
Transcript
WebSockets and Server Sent Events Tuesday, February 5, 13
WebSockets a̶n̶d̶ ̶S̶e̶r̶v̶e̶r̶ ̶S̶e̶n̶t̶ ̶E̶v̶e̶n̶t̶s̶ Tuesday, February 5, 13
WebSockets Tuesday, February 5, 13
Get to know me! • software developer (Ruby, Rails, C,
etc) • http://blog.jonathanrwallace.com/about •
[email protected]
• @jonathanwallace • All around swell guy Tuesday, February 5, 13
Tuesday, February 5, 13
Nature of HTTP • stateless • clients send requests •
servers respond to requests Tuesday, February 5, 13
Tuesday, February 5, 13
“Bi-directional” communication • Comet • Long polling - “you got
anything for me?” • Really only two, “streaming” and “long polling” Tuesday, February 5, 13
Issues? Tuesday, February 5, 13
Long polling Issues? • Header Overhead • Maximal Latency •
Connection Establishment • Allocated Resources • Graceful Degradation • Timeouts • Caching Tuesday, February 5, 13
Streaming Issues? • Framing Techniques • Client Buffering • Network
Intermediaries • Maximal Latency Tuesday, February 5, 13
WebSockets: how they work • client sends specially formatted HTTP
request to server • server must support websocket protocol • that connection is upgraded to a websocket and you can send anything up and down that connection Tuesday, February 5, 13
Tuesday, February 5, 13
Specially formatted request 1 <script text='javascript'> 2 var ws =
new WebSocket('ws://example.com:8080'); 3 </script> Tuesday, February 5, 13
Client side responsibilities 1 <script text='javascript'> 2 # ... 3
ws.onmessage = function(evt) { 4 $("#msg").append("<p>"+evt.data+"</p>"); 5 }; 6 ws.onclose = function() { debug("socket closed"); }; 7 ws.onopen = function() { 8 debug("connected..."); 9 ws.send("hello server"); 10 }; 11 # ... 12 </script> Tuesday, February 5, 13
WebSockets support? Tuesday, February 5, 13
Tuesday, February 5, 13
Tuesday, February 5, 13
Ruby WebSockets server 1 require 'rubygems' 2 require 'em-websocket' 3
4 EventMachine::WebSocket.start( 5 :host => "0.0.0.0", :port => 8080) do |ws| 6 ws.onopen { ws.send "Hello Client!"} 7 ws.onmessage { |msg| ws.send "Pong: #{msg}" } 8 ws.onclose { puts "WebSocket closed" } 9 end Tuesday, February 5, 13
What can you send over WebSockets? Tuesday, February 5, 13
Tuesday, February 5, 13
WebSockets Demo Tuesday, February 5, 13
Tuesday, February 5, 13
Credits • http://www.html5rocks.com/en/tutorials/websockets/basics/ • http://www.html5rocks.com/en/tutorials/eventsource/basics/ • http://tenderlovemaking.com/2012/07/30/is-it-live.html • http://www.ibm.com/developerworks/library/wa-reverseajax1/ •
http://tools.ietf.org/html/draft-loreto-http-bidirectional-07 • https://github.com/igrigorik/em-websocket • http://www.igvita.com/2009/12/22/ruby-websockets-tcp-for-the- browser/ Tuesday, February 5, 13
Images • http://www.flickr.com/photos/67828440@N05/galleries/ 72157632691816485/with/2985066755/#photo_2985066755 • http://betterexplained.com/articles/how-to-optimize-your- site-with-gzip-compression/ Tuesday, February 5,
13
Get to know me! • software developer (Ruby, Rails, C,
etc) • http://blog.jonathanrwallace.com/about •
[email protected]
• @jonathanwallace • All around swell guy Tuesday, February 5, 13