SlideShare a Scribd company logo
WebSocketsA quick tour and demoGaurav OberoiDec 18, 2010 - Chennai Geeks
Who am I?Entrepreneur: started and sold 2 companiesBillMonk (consumer)Precision Polling (SaaS)Programmer, Product Manager:Amazon, Obopay, Xmarks, SurveyMonkeyGeneral geekery:Seattle Tech Startups founder (~2200 member list)TechStars mentor, advisor to startups
What is this talk about?What are WebSockets?Why do we need them?How do we use them?What limitations do they have?
DisclaimerHaven’t deployed production code using WebSockets.Not an expert!
What are WebSockets?+= ?
According to the textbook:WebSocket is a technology for providing bi-directional full duplex communication channels over a single TCP socket.Ahem…
Put simply, WebSockets:Are a new feature in HTML5 (draft) that let you stream data to and from web browsers.
For comparison:Here’s good ol’ HTTP request and response:GET /index.html200 OK (...)With sockets, send data back and forth anytime:
More juicy detailsNew protocol (ws:// and wss://)W3C and IETF standardCurrently a draft, more on this laterUses ports 80 and 443443 recommended for proxy traversalStarts as HTTP, then switches to WSSupports >1 connections over 1 TCP socket
More juicy details: the handshakeClient sends:Server responds:
Yawn…… so why do we need WebSockets?
2 good reasons
First: desire for real-timeWant low latency 2-way communication for:Gaming (pong)Collaboration (live wikis)Dashboards (financial apps)Tracking (watch user actions)Presence (chat with customer support)More!
Second: HTTP doesn’t deliverPeople hack around this (see “Comet”)Polling, long-polling, stream via hidden iframeBUT these are slow, complex, and bulkyOr rely on plugins:Flash, Silverlight, Java appletsBUT these don’t work everywhere (phones)
Damn, this is hairy:Source: http://www.slideshare.net/ismasan/websockets-and-ruby-eventmachine
Vs. HTTP hacks, Websockets provide:Lower latency: no new TCP connections for each HTTP requestLower overhead: for each message sent(2 bytes vs. lines of HTTP header junk)Less traffic: since clients don’t need to poll, messages only sent when we have data
How do we use WebSockets?
What you’ll need:WebSockets compliant browserWebKit: Chrome, Safari (works on iOS)Client Javascript APIServer-side API
Client API in JavascriptInitialize:varws = new WebSocket(“ws://example.com”)Send data:send(data)Event-handlers:onopenonmessageoncloseonerror
Server-side APIThreaded servers can be used but not recommended:1 thread/process per socket  memory hog!Evented-servers are ideal:1 process handles all requestsWaits for I/O before processing requests (reactor pattern)Suggested servers:Ruby: Event Machine + em-websocketJavascript: Node.js + WebSocket modulePython: Twisted + txWebSocket
DEMO TIME!
What limitations do WebSockets have?
First, the big onesNot all browsers support themNo support in Firefox 4, IE9, OperaSo you need to fallback to something that worksSee Socket.IO: client and server library for graceful fallbackDraft spec in jeopardy after Dec 8 security announcement by MozillaSecurity vulnerabilities with transparent proxiesNot caused by WebSockets, but they expose issueMy guess: we’ll get by this with some spec changes
And the other thingsWebSockets need maintenance and care:Re-open connif network hiccup or timeoutBack off if server is down, don’t keep tryingKeep alive if your connection times outBuffer and re-send msgs in the above casesMy guess: libraries will fill in these gaps
In ConclusionWebSockets == “TCP for the Web”Easy JS library, evented-servers on the backNot prod ready, but soon (fingers crossed)Check out some demos:http://websockets.org/demos.html
twitter.com/goberoi

More Related Content

What's hot (20)

PDF
Introduction to WebSockets
Gunnar Hillert
 
PPTX
Web api
Sudhakar Sharma
 
PPTX
HTML5 WebSocket Introduction
Marcelo Jabali
 
PPTX
Json Web Token - JWT
Prashant Walke
 
PPTX
Cookies and sessions
Sukrit Gupta
 
PPT
RESTful services
gouthamrv
 
PPTX
Servlets
ZainabNoorGul
 
PPTX
Rest API
Rohana K Amarakoon
 
PDF
Lecture 3: Servlets - Session Management
Fahad Golra
 
PPTX
SignalR with asp.net
Martin Bodocky
 
PPTX
Spring boot Introduction
Jeevesh Pandey
 
PDF
Express node js
Yashprit Singh
 
PDF
Cross Origin Resource Sharing
Luke Weerasooriya
 
PPTX
Springboot Microservices
NexThoughts Technologies
 
PPTX
What Is Express JS?
Simplilearn
 
PPTX
Waf bypassing Techniques
Avinash Thapa
 
ODP
Introduction to Swagger
Knoldus Inc.
 
PPT
Understanding REST
Nitin Pande
 
PPTX
Introducing Swagger
Tony Tam
 
PPT
Node.js Express Framework
TheCreativedev Blog
 
Introduction to WebSockets
Gunnar Hillert
 
HTML5 WebSocket Introduction
Marcelo Jabali
 
Json Web Token - JWT
Prashant Walke
 
Cookies and sessions
Sukrit Gupta
 
RESTful services
gouthamrv
 
Servlets
ZainabNoorGul
 
Lecture 3: Servlets - Session Management
Fahad Golra
 
SignalR with asp.net
Martin Bodocky
 
Spring boot Introduction
Jeevesh Pandey
 
Express node js
Yashprit Singh
 
Cross Origin Resource Sharing
Luke Weerasooriya
 
Springboot Microservices
NexThoughts Technologies
 
What Is Express JS?
Simplilearn
 
Waf bypassing Techniques
Avinash Thapa
 
Introduction to Swagger
Knoldus Inc.
 
Understanding REST
Nitin Pande
 
Introducing Swagger
Tony Tam
 
Node.js Express Framework
TheCreativedev Blog
 

Similar to Intro to WebSockets (20)

PPTX
Intro to Web Sockets
Jim Gourgoutis
 
PPTX
Web sockets - Pentesting
Vandana Verma
 
PPTX
WebSockets in JEE 7
Shahzad Badar
 
PPTX
WebSockets-Revolutionizing-Real-Time-Communication.pptx
YasserLina
 
PDF
Dev con kolkata 2012 websockets
SANKARSAN BOSE
 
PPTX
ClientServer Websocket.pptx
MaxamedSheekhAmiin
 
PDF
Programming WebSockets - OSCON 2010
sullis
 
PPTX
Websockets: Pushing the web forward
Mark Roden
 
PPTX
Html5 websockets
AbhishekMondal42
 
PPTX
presentation in .net programming web sockets.pptx
ArvieJayLapig
 
PPTX
Training Webinar: Enterprise application performance with server push technol...
OutSystems
 
PPTX
Enhancing Mobile User Experience with WebSocket
Mauricio "Maltron" Leal
 
PPT
Web-Socket
Pankaj Kumar Sharma
 
PPTX
WebSockets On Fire
Jef Claes
 
PDF
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
Viktor Gamov
 
PPTX
Introduction of WebSockets
Mike Budhani
 
PPTX
Understand WebSockets
Ashish Kumar
 
PPTX
Webinar slides "Building Real-Time Collaborative Web Applications"
Sachin Katariya
 
PPTX
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
Ericom Software
 
PPTX
vlavrynovych - WebSockets Presentation
Volodymyr Lavrynovych
 
Intro to Web Sockets
Jim Gourgoutis
 
Web sockets - Pentesting
Vandana Verma
 
WebSockets in JEE 7
Shahzad Badar
 
WebSockets-Revolutionizing-Real-Time-Communication.pptx
YasserLina
 
Dev con kolkata 2012 websockets
SANKARSAN BOSE
 
ClientServer Websocket.pptx
MaxamedSheekhAmiin
 
Programming WebSockets - OSCON 2010
sullis
 
Websockets: Pushing the web forward
Mark Roden
 
Html5 websockets
AbhishekMondal42
 
presentation in .net programming web sockets.pptx
ArvieJayLapig
 
Training Webinar: Enterprise application performance with server push technol...
OutSystems
 
Enhancing Mobile User Experience with WebSocket
Mauricio "Maltron" Leal
 
WebSockets On Fire
Jef Claes
 
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
Viktor Gamov
 
Introduction of WebSockets
Mike Budhani
 
Understand WebSockets
Ashish Kumar
 
Webinar slides "Building Real-Time Collaborative Web Applications"
Sachin Katariya
 
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
Ericom Software
 
vlavrynovych - WebSockets Presentation
Volodymyr Lavrynovych
 
Ad

Intro to WebSockets

  • 1. WebSocketsA quick tour and demoGaurav OberoiDec 18, 2010 - Chennai Geeks
  • 2. Who am I?Entrepreneur: started and sold 2 companiesBillMonk (consumer)Precision Polling (SaaS)Programmer, Product Manager:Amazon, Obopay, Xmarks, SurveyMonkeyGeneral geekery:Seattle Tech Startups founder (~2200 member list)TechStars mentor, advisor to startups
  • 3. What is this talk about?What are WebSockets?Why do we need them?How do we use them?What limitations do they have?
  • 4. DisclaimerHaven’t deployed production code using WebSockets.Not an expert!
  • 6. According to the textbook:WebSocket is a technology for providing bi-directional full duplex communication channels over a single TCP socket.Ahem…
  • 7. Put simply, WebSockets:Are a new feature in HTML5 (draft) that let you stream data to and from web browsers.
  • 8. For comparison:Here’s good ol’ HTTP request and response:GET /index.html200 OK (...)With sockets, send data back and forth anytime:
  • 9. More juicy detailsNew protocol (ws:// and wss://)W3C and IETF standardCurrently a draft, more on this laterUses ports 80 and 443443 recommended for proxy traversalStarts as HTTP, then switches to WSSupports >1 connections over 1 TCP socket
  • 10. More juicy details: the handshakeClient sends:Server responds:
  • 11. Yawn…… so why do we need WebSockets?
  • 13. First: desire for real-timeWant low latency 2-way communication for:Gaming (pong)Collaboration (live wikis)Dashboards (financial apps)Tracking (watch user actions)Presence (chat with customer support)More!
  • 14. Second: HTTP doesn’t deliverPeople hack around this (see “Comet”)Polling, long-polling, stream via hidden iframeBUT these are slow, complex, and bulkyOr rely on plugins:Flash, Silverlight, Java appletsBUT these don’t work everywhere (phones)
  • 15. Damn, this is hairy:Source: http://www.slideshare.net/ismasan/websockets-and-ruby-eventmachine
  • 16. Vs. HTTP hacks, Websockets provide:Lower latency: no new TCP connections for each HTTP requestLower overhead: for each message sent(2 bytes vs. lines of HTTP header junk)Less traffic: since clients don’t need to poll, messages only sent when we have data
  • 17. How do we use WebSockets?
  • 18. What you’ll need:WebSockets compliant browserWebKit: Chrome, Safari (works on iOS)Client Javascript APIServer-side API
  • 19. Client API in JavascriptInitialize:varws = new WebSocket(“ws://example.com”)Send data:send(data)Event-handlers:onopenonmessageoncloseonerror
  • 20. Server-side APIThreaded servers can be used but not recommended:1 thread/process per socket  memory hog!Evented-servers are ideal:1 process handles all requestsWaits for I/O before processing requests (reactor pattern)Suggested servers:Ruby: Event Machine + em-websocketJavascript: Node.js + WebSocket modulePython: Twisted + txWebSocket
  • 22. What limitations do WebSockets have?
  • 23. First, the big onesNot all browsers support themNo support in Firefox 4, IE9, OperaSo you need to fallback to something that worksSee Socket.IO: client and server library for graceful fallbackDraft spec in jeopardy after Dec 8 security announcement by MozillaSecurity vulnerabilities with transparent proxiesNot caused by WebSockets, but they expose issueMy guess: we’ll get by this with some spec changes
  • 24. And the other thingsWebSockets need maintenance and care:Re-open connif network hiccup or timeoutBack off if server is down, don’t keep tryingKeep alive if your connection times outBuffer and re-send msgs in the above casesMy guess: libraries will fill in these gaps
  • 25. In ConclusionWebSockets == “TCP for the Web”Easy JS library, evented-servers on the backNot prod ready, but soon (fingers crossed)Check out some demos:http://websockets.org/demos.html