$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Websockets
Search
Jonathan Wallace
February 05, 2013
Programming
2
130
Websockets
Review websockets, what they are and give a simple example
Jonathan Wallace
February 05, 2013
Tweet
Share
More Decks by Jonathan Wallace
See All by Jonathan Wallace
Modern Data Literacy
jwallace
0
140
Tailoring Mentorship (with speaker notes)
jwallace
0
350
Tailoring Mentorship (only slides)
jwallace
0
450
Trusty URIs
jwallace
0
140
Navigating Your Options for Mobile App Development
jwallace
1
150
Effective Debugging - Big Nerd Ranch Tech Talk
jwallace
2
210
Effective Debugging Rubyconf
jwallace
2
340
Importance of IS in Startups
jwallace
0
82
Chef and puppet
jwallace
0
130
Other Decks in Programming
See All in Programming
Rediscover the Console - SymfonyCon Amsterdam 2025
chalasr
2
170
S3 VectorsとStrands Agentsを利用したAgentic RAGシステムの構築
tosuri13
6
330
LLMで複雑な検索条件アセットから脱却する!! 生成的検索インタフェースの設計論
po3rin
4
830
開発に寄りそう自動テストの実現
goyoki
2
1.1k
Integrating WordPress and Symfony
alexandresalome
0
160
ローターアクトEクラブ アメリカンナイト:川端 柚菜 氏(Japan O.K. ローターアクトEクラブ 会長):2720 Japan O.K. ロータリーEクラブ2025年12月1日卓話
2720japanoke
0
730
FluorTracer / RayTracingCamp11
kugimasa
0
240
AtCoder Conference 2025「LLM時代のAHC」
imjk
2
520
脳の「省エネモード」をデバッグする ~System 1(直感)と System 2(論理)の切り替え~
panda728
PRO
0
100
実は歴史的なアップデートだと思う AWS Interconnect - multicloud
maroon1st
0
210
「コードは上から下へ読むのが一番」と思った時に、思い出してほしい話
panda728
PRO
39
26k
C-Shared Buildで突破するAI Agent バックテストの壁
po3rin
0
390
Featured
See All Featured
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Side Projects
sachag
455
43k
Unsuck your backbone
ammeep
671
58k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Documentation Writing (for coders)
carmenintech
77
5.2k
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Agile that works and the tools we love
rasmusluckow
331
21k
The Cult of Friendly URLs
andyhume
79
6.7k
RailsConf 2023
tenderlove
30
1.3k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
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