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!

Recommended for you

REST API and CRUD
REST API and CRUDREST API and CRUD
REST API and CRUD

A REST API uses HTTP requests with verbs like GET, POST, PUT, and DELETE to perform CRUD (Create, Read, Update, Delete) operations on resources identified by URLs. It provides a lightweight alternative to SOAP that returns data in JSON format and HTTP response codes. Well-known codes include 200 for OK, 201 for Created, 400 for Bad Request, and 404 for Not Found. REST enables building applications and platforms that can easily integrate new interfaces over time.

crudcrud applicationwhat is crud
REST & RESTful Web Services
REST & RESTful Web ServicesREST & RESTful Web Services
REST & RESTful Web Services

An introduction to REST and RESTful web services. You can take the course below to learn about REST & RESTful web services. https://www.udemy.com/building-php-restful-web-services/

information technologyweb servicecloud computing
Simple Object Access Protocol
Simple Object Access ProtocolSimple Object Access Protocol
Simple Object Access Protocol

This document discusses Simple Object Access Protocol (SOAP). SOAP allows applications to exchange information over HTTP and is independent of platform and language. A SOAP message contains an envelope, header, body, and optional fault. The envelope defines the message as SOAP. The header contains application-specific metadata. The body contains the call and response. Fault indicates any errors. SOAP uses HTTP for transport and is XML-based, allowing it to penetrate firewalls.

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:

Recommended for you

Http protocol
Http protocolHttp protocol
Http protocol

HTTP is an application-level protocol for distributed, collaborative hypermedia systems that has been used by the World Wide Web since 1990. The initial HTTP/0.9 version provided a simple protocol for raw data transfer, while HTTP/1.0 introduced MIME-like messages to include meta information and request/response modifiers. HTTP/1.0 did not sufficiently account for hierarchical proxies, caching, persistent connections or virtual hosts. HTTP sits at the top of the TCP/IP stack and uses ports to carry protocols between services, with HTTP typically using port 80. An HTTP message is delivered over a TCP/IP connection by chopping the message into chunks small enough to fit in TCP segments, which are then sent inside IP datagrams

An Overview of Web Services: SOAP and REST
An Overview of Web Services: SOAP and REST An Overview of Web Services: SOAP and REST
An Overview of Web Services: SOAP and REST

The presentation provides an overview of what are Web Services, Why we need for Web Services; Features of SOAP & RESTful Web Services.

web servicesoapsoa
HyperText Transfer Protocol (HTTP)
HyperText Transfer Protocol (HTTP)HyperText Transfer Protocol (HTTP)
HyperText Transfer Protocol (HTTP)

HTTP is the application-layer protocol for transmitting hypertext documents across the internet. It works by establishing a TCP connection between an HTTP client, like a web browser, and an HTTP server. The client sends a request to the server using methods like GET or POST. The server responds with a status code and the requested resource. HTTP is stateless, meaning each request is independent and servers do not remember past client interactions. Cookies and caching are techniques used to maintain some state and improve performance.

pipeliningcachehow http works
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

Recommended for you

SOAP - Simple Object Access Protocol
SOAP - Simple Object Access ProtocolSOAP - Simple Object Access Protocol
SOAP - Simple Object Access Protocol

A detailed description of Simple Object Access Protocol (SOAP) Content: What is SOAP? Why SOAP? SOAP Transport Methods SOAP Messaging Framework SOAP Message SOAP Request Message SOAP Response Message Pros & Cons of SOAP References provided

soapweb serviceshttp
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web API

The document provides an introduction to web APIs and REST. It defines APIs as methods to access data and workflows from an application without using the application itself. It describes REST as an architectural style for APIs that uses a client-server model with stateless operations and a uniform interface. The document outlines best practices for REST APIs, including using HTTP verbs like GET, POST, PUT and DELETE to perform CRUD operations on resources identified by URIs. It also discusses authentication, authorization, security concerns and gives examples of popular REST APIs from Facebook, Twitter and other services.

restapi
HTTP Request and Response Structure
HTTP Request and Response StructureHTTP Request and Response Structure
HTTP Request and Response Structure

https://www.youtube.com/watch?v=lKrbeJ7-J98 HTTP messages are how data is exchanged between a server and a client. There are two types of messages: requests sent by the client to trigger an action on the server, and responses, the answer from the server.

infosecgirlshttpcrlf
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

Recommended for you

Https presentation
Https presentationHttps presentation
Https presentation

HTTPS is a protocol that combines HTTP with SSL/TLS encryption to provide secure communication between a client and server. It encrypts data sent between a browser and website using a public/private key system. When a client requests an HTTPS connection, the website sends its SSL certificate containing a public key. This begins the SSL handshake where shared secrets are generated to uniquely encrypt the connection. HTTPS is important for securing sensitive communications and establishing trust, as it is used widely on banking, payment, shopping and email sites.

jatin patel
Http and its Applications
Http and its ApplicationsHttp and its Applications
Http and its Applications

HTTP is an application-level protocol for distributed, collaborative hypermedia information systems. It is based on the client-server model and uses TCP/IP protocols. HTTP functions by having clients make requests to servers, which respond with status codes and requested resources. Key aspects of HTTP include its stateless and connectionless nature, as well as its use of request methods like GET and POST.

engineeringtechnologynetworking
Learn react-js
Learn react-jsLearn react-js
Learn react-js

The document provides an introduction to ReactJS, including: - ReactJS is a JavaScript library developed by Facebook for building user interfaces. - It uses virtual DOM for rendering UI components efficiently. Only updated components are re-rendered. - Components are the basic building blocks of React apps. They accept input and return React elements to describe what should appear on the screen. - The main steps to set up a React app are installing React and ReactDOM libraries, adding JSX syntax, and rendering components onto the DOM using ReactDOM.render().

javascriptreactjsapps
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

Recommended for you

Restful web services ppt
Restful web services pptRestful web services ppt
Restful web services ppt

The document provides an overview of a seminar on RESTful web services. It discusses what REST is, its characteristics and principles, and compares RESTful architectures to SOAP. Key points covered include how REST focuses on a system's resources and how they are addressed and transferred over HTTP, the client-server interaction style of REST, and advantages of REST like scalability and loose coupling between components.

Hypertext transfer protocol and hypertext transfer protocol secure(HTTP and H...
Hypertext transfer protocol and hypertext transfer protocol secure(HTTP and H...Hypertext transfer protocol and hypertext transfer protocol secure(HTTP and H...
Hypertext transfer protocol and hypertext transfer protocol secure(HTTP and H...

The document defines HTTP and HTTPS. HTTP is the Hypertext Transfer Protocol that provides communication between web browsers and servers. It is unsecured and transmits data in plain text. HTTPS is HTTP secured with SSL/TLS encryption to provide security. Key differences are that HTTPS uses port 443 instead of HTTP's port 80, establishes an encrypted channel, and verifies servers with certificates to protect against attacks.

OpenSSL
OpenSSLOpenSSL
OpenSSL

SSL and certificates exist to provide encryption and identification for secure communication between web servers and clients. OpenSSL is a cryptography library and toolkit that implements the SSL and TLS protocols, providing encryption through different ciphers and algorithms. It is widely used by over 60% of web servers to generate private keys, certificate signing requests, and perform encryption and decryption as well as manage certificates.

opensslcyber securitydata encryption
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

Recommended for you

Http methods
Http methodsHttp methods
Http methods

1. The document describes the common HTTP methods used to retrieve or send data over the web, including GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, and TRACE. 2. GET is used to retrieve a resource, HEAD is like GET but only returns headers, and POST sends data to a server like form data or file uploads. 3. PUT replaces a resource with uploaded content, DELETE removes a resource, and CONNECT establishes a tunnel. OPTIONS returns supported methods and TRACE echoes a request for debugging.

http methodshttpmethods of http
Introduction to API
Introduction to APIIntroduction to API
Introduction to API

The document discusses APIs, defining them as interfaces that allow applications to communicate and share data over a network. It notes that APIs act as an interface between clients and servers, exposing backend data through operations, inputs, outputs, and data types. The document also outlines the benefits of APIs in standardizing communication and enabling reusability. It introduces common API terminology and types, focusing on web APIs which are the most widely used.

introduction to apiapimulesoft
HTML5 WebSocket: The New Network Stack for the Web
HTML5 WebSocket: The New Network Stack for the WebHTML5 WebSocket: The New Network Stack for the Web
HTML5 WebSocket: The New Network Stack for the Web

Presentation given on Feb. 11, 2011 at the New York HTML5 User Group by Peter Lubbers and Frank Greco

web socketsweb socketconnectivity
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

HTTP request and response
HTTP request and responseHTTP request and response
HTTP request and response
Sahil Agarwal
 
Web services SOAP
Web services SOAPWeb services SOAP
Web services SOAP
princeirfancivil
 
HTTP Basics
HTTP BasicsHTTP Basics
HTTP Basics
sanjoysanyal
 
REST API and CRUD
REST API and CRUDREST API and CRUD
REST API and CRUD
Prem Sanil
 
REST & RESTful Web Services
REST & RESTful Web ServicesREST & RESTful Web Services
REST & RESTful Web Services
Halil Burak Cetinkaya
 
Simple Object Access Protocol
Simple Object Access ProtocolSimple Object Access Protocol
Simple Object Access Protocol
Saatviga Sudhahar
 
Http protocol
Http protocolHttp protocol
Http protocol
Arpita Naik
 
An Overview of Web Services: SOAP and REST
An Overview of Web Services: SOAP and REST An Overview of Web Services: SOAP and REST
An Overview of Web Services: SOAP and REST
Ram Awadh Prasad, PMP
 
HyperText Transfer Protocol (HTTP)
HyperText Transfer Protocol (HTTP)HyperText Transfer Protocol (HTTP)
HyperText Transfer Protocol (HTTP)
Gurjot Singh
 
SOAP - Simple Object Access Protocol
SOAP - Simple Object Access ProtocolSOAP - Simple Object Access Protocol
SOAP - Simple Object Access Protocol
Anushka Patil
 
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web API
Brad Genereaux
 
HTTP Request and Response Structure
HTTP Request and Response StructureHTTP Request and Response Structure
HTTP Request and Response Structure
BhagyashreeGajera1
 
Https presentation
Https presentationHttps presentation
Https presentation
patel jatin
 
Http and its Applications
Http and its ApplicationsHttp and its Applications
Http and its Applications
Nayan Dagliya
 
Learn react-js
Learn react-jsLearn react-js
Restful web services ppt
Restful web services pptRestful web services ppt
Hypertext transfer protocol and hypertext transfer protocol secure(HTTP and H...
Hypertext transfer protocol and hypertext transfer protocol secure(HTTP and H...Hypertext transfer protocol and hypertext transfer protocol secure(HTTP and H...
Hypertext transfer protocol and hypertext transfer protocol secure(HTTP and H...
rahul kundu
 
OpenSSL
OpenSSLOpenSSL
OpenSSL
Timbal Mayank
 
Http methods
Http methodsHttp methods
Http methods
maamir farooq
 
Introduction to API
Introduction to APIIntroduction to API
Introduction to API
rajnishjha29
 

What's hot (20)

HTTP request and response
HTTP request and responseHTTP request and response
HTTP request and response
 
Web services SOAP
Web services SOAPWeb services SOAP
Web services SOAP
 
HTTP Basics
HTTP BasicsHTTP Basics
HTTP Basics
 
REST API and CRUD
REST API and CRUDREST API and CRUD
REST API and CRUD
 
REST & RESTful Web Services
REST & RESTful Web ServicesREST & RESTful Web Services
REST & RESTful Web Services
 
Simple Object Access Protocol
Simple Object Access ProtocolSimple Object Access Protocol
Simple Object Access Protocol
 
Http protocol
Http protocolHttp protocol
Http protocol
 
An Overview of Web Services: SOAP and REST
An Overview of Web Services: SOAP and REST An Overview of Web Services: SOAP and REST
An Overview of Web Services: SOAP and REST
 
HyperText Transfer Protocol (HTTP)
HyperText Transfer Protocol (HTTP)HyperText Transfer Protocol (HTTP)
HyperText Transfer Protocol (HTTP)
 
SOAP - Simple Object Access Protocol
SOAP - Simple Object Access ProtocolSOAP - Simple Object Access Protocol
SOAP - Simple Object Access Protocol
 
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web API
 
HTTP Request and Response Structure
HTTP Request and Response StructureHTTP Request and Response Structure
HTTP Request and Response Structure
 
Https presentation
Https presentationHttps presentation
Https presentation
 
Http and its Applications
Http and its ApplicationsHttp and its Applications
Http and its Applications
 
Learn react-js
Learn react-jsLearn react-js
Learn react-js
 
Restful web services ppt
Restful web services pptRestful web services ppt
Restful web services ppt
 
Hypertext transfer protocol and hypertext transfer protocol secure(HTTP and H...
Hypertext transfer protocol and hypertext transfer protocol secure(HTTP and H...Hypertext transfer protocol and hypertext transfer protocol secure(HTTP and H...
Hypertext transfer protocol and hypertext transfer protocol secure(HTTP and H...
 
OpenSSL
OpenSSLOpenSSL
OpenSSL
 
Http methods
Http methodsHttp methods
Http methods
 
Introduction to API
Introduction to APIIntroduction to API
Introduction to API
 

Similar to Intro to WebSockets

HTML5 WebSocket: The New Network Stack for the Web
HTML5 WebSocket: The New Network Stack for the WebHTML5 WebSocket: The New Network Stack for the Web
HTML5 WebSocket: The New Network Stack for the Web
Peter Lubbers
 
WebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! FrameworkWebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! Framework
Fabio Tiriticco
 
The HTML5 WebSocket API
The HTML5 WebSocket APIThe HTML5 WebSocket API
The HTML5 WebSocket API
David Lindkvist
 
Web sockets - Pentesting
Web sockets - Pentesting Web sockets - Pentesting
Web sockets - Pentesting
Vandana Verma
 
Ajax and PHP
Ajax and PHPAjax and PHP
Ajax and PHP
John Coggeshall
 
Monitoring as an entry point for collaboration
Monitoring as an entry point for collaborationMonitoring as an entry point for collaboration
Monitoring as an entry point for collaboration
Julien Pivotto
 
Websocket technology for XPages
Websocket technology for XPagesWebsocket technology for XPages
Websocket technology for XPages
Csaba Kiss
 
Websocket vs SSE - Paris.js - 24/06/15
Websocket vs SSE - Paris.js - 24/06/15Websocket vs SSE - Paris.js - 24/06/15
Websocket vs SSE - Paris.js - 24/06/15
streamdata.io
 
API Design and WebSocket
API Design and WebSocketAPI Design and WebSocket
API Design and WebSocket
Frank Greco
 
Behind the scenes of Real-Time Notifications
Behind the scenes of Real-Time NotificationsBehind the scenes of Real-Time Notifications
Behind the scenes of Real-Time Notifications
Guillermo Mansilla
 
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
Ericom Software
 
Spring Cloud Gateway - Nate Schutta
Spring Cloud Gateway - Nate SchuttaSpring Cloud Gateway - Nate Schutta
Spring Cloud Gateway - Nate Schutta
VMware Tanzu
 
Dev con kolkata 2012 websockets
Dev con kolkata 2012   websocketsDev con kolkata 2012   websockets
Dev con kolkata 2012 websockets
SANKARSAN BOSE
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
Joseph de Castelnau
 
Websocket
WebsocketWebsocket
Websocket
艾鍗科技
 
Building interactivity with websockets
Building interactivity with websocketsBuilding interactivity with websockets
Building interactivity with websockets
Wim Godden
 
Node Js Websocket Js Meetup Slides
Node Js Websocket Js Meetup SlidesNode Js Websocket Js Meetup Slides
Node Js Websocket Js Meetup Slides
Makoto Inoue
 
The Web, After HTML5
The Web, After HTML5The Web, After HTML5
The Web, After HTML5
Jonathan Jeon
 
Ws
WsWs
CodeCamp Iasi 10 March 2012 - Gabriel Enea - ASP.NET Web API
CodeCamp Iasi 10 March 2012 -   Gabriel Enea - ASP.NET Web APICodeCamp Iasi 10 March 2012 -   Gabriel Enea - ASP.NET Web API
CodeCamp Iasi 10 March 2012 - Gabriel Enea - ASP.NET Web API
Codecamp Romania
 

Similar to Intro to WebSockets (20)

HTML5 WebSocket: The New Network Stack for the Web
HTML5 WebSocket: The New Network Stack for the WebHTML5 WebSocket: The New Network Stack for the Web
HTML5 WebSocket: The New Network Stack for the Web
 
WebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! FrameworkWebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! Framework
 
The HTML5 WebSocket API
The HTML5 WebSocket APIThe HTML5 WebSocket API
The HTML5 WebSocket API
 
Web sockets - Pentesting
Web sockets - Pentesting Web sockets - Pentesting
Web sockets - Pentesting
 
Ajax and PHP
Ajax and PHPAjax and PHP
Ajax and PHP
 
Monitoring as an entry point for collaboration
Monitoring as an entry point for collaborationMonitoring as an entry point for collaboration
Monitoring as an entry point for collaboration
 
Websocket technology for XPages
Websocket technology for XPagesWebsocket technology for XPages
Websocket technology for XPages
 
Websocket vs SSE - Paris.js - 24/06/15
Websocket vs SSE - Paris.js - 24/06/15Websocket vs SSE - Paris.js - 24/06/15
Websocket vs SSE - Paris.js - 24/06/15
 
API Design and WebSocket
API Design and WebSocketAPI Design and WebSocket
API Design and WebSocket
 
Behind the scenes of Real-Time Notifications
Behind the scenes of Real-Time NotificationsBehind the scenes of Real-Time Notifications
Behind the scenes of Real-Time Notifications
 
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
 
Spring Cloud Gateway - Nate Schutta
Spring Cloud Gateway - Nate SchuttaSpring Cloud Gateway - Nate Schutta
Spring Cloud Gateway - Nate Schutta
 
Dev con kolkata 2012 websockets
Dev con kolkata 2012   websocketsDev con kolkata 2012   websockets
Dev con kolkata 2012 websockets
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 
Websocket
WebsocketWebsocket
Websocket
 
Building interactivity with websockets
Building interactivity with websocketsBuilding interactivity with websockets
Building interactivity with websockets
 
Node Js Websocket Js Meetup Slides
Node Js Websocket Js Meetup SlidesNode Js Websocket Js Meetup Slides
Node Js Websocket Js Meetup Slides
 
The Web, After HTML5
The Web, After HTML5The Web, After HTML5
The Web, After HTML5
 
Ws
WsWs
Ws
 
CodeCamp Iasi 10 March 2012 - Gabriel Enea - ASP.NET Web API
CodeCamp Iasi 10 March 2012 -   Gabriel Enea - ASP.NET Web APICodeCamp Iasi 10 March 2012 -   Gabriel Enea - ASP.NET Web API
CodeCamp Iasi 10 March 2012 - Gabriel Enea - ASP.NET Web API
 

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