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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
460
Trusty URIs
jwallace
0
160
Navigating Your Options for Mobile App Development
jwallace
1
170
Effective Debugging - Big Nerd Ranch Tech Talk
jwallace
2
220
Effective Debugging Rubyconf
jwallace
2
360
Importance of IS in Startups
jwallace
0
110
Chef and puppet
jwallace
0
150
Other Decks in Programming
See All in Programming
Spec Driven Development | AI Summit Vilnius
danielsogl
PRO
1
150
Terraform言語の静的解析 / static analysis of Terraform language
wata727
1
140
PicoRuby for IoT: Connecting to the Cloud with MQTT
yuuu
2
770
実用!Hono RPC2026
yodaka
2
310
検索設計から 推論設計への重心移動と Recall-First Retrieval
po3rin
5
1.6k
「OSSがあるなら自作するな」は AI時代も正しいか ── Build vs Adopt の新しい判断基準
kumorn5s
7
2.5k
Kingdom of the Machine
yui_knk
2
1.5k
How We Benchmarked Quarkus: Patterns and anti-patterns
hollycummins
1
190
AI時代のエンジニアリングの原則 / Engineering Principles in the AI Era
haru860
0
1.1k
Agentic UI in the Frontend: Architectures with Open Standards @JAX 2026 in Mainz
manfredsteyer
PRO
0
110
リセットCSSを1行消したらアクセシビリティが向上した話
pvcresin
4
500
tRPCの概要と少しだけパフォーマンス
misoton665
2
270
Featured
See All Featured
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
110
Information Architects: The Missing Link in Design Systems
soysaucechin
0
920
Marketing to machines
jonoalderson
1
5.2k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.9k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
180
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.4k
A Modern Web Designer's Workflow
chriscoyier
698
190k
Darren the Foodie - Storyboard
khoart
PRO
3
3.3k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.8k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
360
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