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
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
180
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
380
Importance of IS in Startups
jwallace
0
110
Chef and puppet
jwallace
0
150
Other Decks in Programming
See All in Programming
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
260
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
220
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
10
3.7k
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
3.7k
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
7
4.2k
Lessons from Spec-Driven Development
simas
PRO
0
180
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2k
OSもどきOS
arkw
0
560
決定論的オーケストレーションの設計と実装 / Design and Implementation of Deterministic Orchestration
nrslib
3
1.3k
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
570
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
130
New "Type" system on PicoRuby
pocke
1
850
Featured
See All Featured
Joys of Absence: A Defence of Solitary Play
codingconduct
1
390
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.5k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.3k
We Are The Robots
honzajavorek
0
250
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
71
40k
Making the Leap to Tech Lead
cromwellryan
135
9.9k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
590
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.8k
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.7k
How to make the Groovebox
asonas
2
2.2k
What does AI have to do with Human Rights?
axbom
PRO
1
2.2k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
160
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