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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
390
Tailoring Mentorship (only slides)
jwallace
0
480
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
120
Chef and puppet
jwallace
0
160
Other Decks in Programming
See All in Programming
【やさしく解説 設計編 #0】DDDのコード、読めるのに分からない人へ
panda728
PRO
2
290
JAWS-UG横浜 #102 AWSサ終供養LT会 成仏できない AWS サービスたち 〜本日、三体供養します〜
maroon1st
0
280
Go言語とトイモデルで学ぶTransformerの気持ち / fukuokago23-transformer
monochromegane
0
150
torikago - Ruby::Boxで照らすモジュラモノリスの実行境界
se4weed
1
290
Build-to-own AI: Agentic Development for Humans
inesmontani
PRO
0
130
yield再入門 #phpcon
o0h
PRO
0
840
これって Effect でできたのでは? / TSKaigi Mashup Kansai #2
susisu
0
130
為什麼你並不需要ViewModel / No, you don't need a ViewModel
lovee
1
450
Lean は証明の正しさを確認するためだけのツールって思ってませんか?
inoueasei
1
130
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
1
500
メールのエイリアス機能を履き違えない
isshinfunada
0
160
その節約、円になってますか?
isamumumu
0
590
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.2k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
230
Producing Creativity
orderedlist
PRO
348
40k
Ethics towards AI in product and experience design
skipperchong
2
330
What does AI have to do with Human Rights?
axbom
PRO
1
2.3k
AI: The stuff that nobody shows you
jnunemaker
PRO
9
850
Ruling the World: When Life Gets Gamed
codingconduct
0
290
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
920
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.1k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
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