Socket.io

Timothy Fitz
Timothy FitzIndependent Contractor at Timothy Fitz
The cross-browser, cross-device WebSocket
WebSocket
• Ideal transport for realtime web
  applications
• TCP for the web
• Bi-directional full-duplex communication
• Firefox 4 (beta), Google Chrome 4, Safari 5
• Draft, evolving protocol under constant
  revision/changes.
  http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol
WebSocket is simple
• Conceived with the idea of simplicity for
  the client-side developer and the server
  implementor.
• The Socket.IO Node.JS WebSocket server
  is ~130 LOC
• Yes, you can implement a scalable HTTP 1.1
  server with WebSocket support in 130
  LOC in JavaScript.
WebSocket is simple
var a = new WebSocket(‘ws://localhost’);
a.onopen = function(){
  alert(‘connected’);
}
a.onmessage = function(ev){
  alert(ev.data);
}
a.onclose = function(){
  alert(‘disconnected’);
}
WebSocket                                    AJAX
var a = new WebSocket(‘ws://localhost/w’);   var a = new XMLHttpRequest();
a.onopen = function(){                       a.onreadystatechange = function(){
   alert(‘connected’);                          if (this.readyState == 4){
   a.send(‘hello there’);                          alert(this.responseText);
}                                               }
a.onmessage = function(ev){                  });
   alert(ev.data);                           a.open(‘GET’, ‘/some/url’);
}                                            a.send();
a.onclose = function(){
   alert(‘disconnected’);
}
WebSocket                                         AJAX
var a = new WebSocket(‘ws://localhost/w’);        var a = new XMLHttpRequest();
a.onopen = function(){                            a.onreadystatechange = function(){
   alert(‘connected’);                               if (this.readyState == 4){
   a.send(‘hello there’);                               alert(this.responseText);
}                                                    }
a.onmessage = function(ev){                       });
   alert(ev.data);                                a.open(‘GET’, ‘/some/url’);
}                                                 a.send();
a.onclose = function(){
   alert(‘disconnected’);
}



•   Connection stays open and messages are sent   •   Connection opens, headers are sent, response is
                                                      emitted, connection is closed.
    bi-directionally.

•   Sends raw data from one point to the other,   •   GET, POST, PUT, DELETE,PATCH HTTP
                                                      commands.
    doesn’t know any commands

•   Ideal for realtime interactions               •   Ideal for traditional interactions

•   Limited browser support.                      •   Limited browser support
How about cross browser support?




  To illustrate, let’s look at how people are using
                       AJAX today
How about cross browser support?

jQuery
                               •   API on top of XMLHTTPRequest

$.ajax({                       •   Solves the differences between browsers,
   url: ‘/some/url’,               (implements MSXML ActiveX object for IE6)
   complete: function(data){
      // do something              and works on almost every user agent.
   }
})
                               •   Makes it even easier to write async requests

                               •   Adds *new features* that the standard doesn’t
                                   support (timeouts, caching, filters, etc)
How about cross browser support?

Socket.IO                        •   API on top of WebSocket, Flash, Long Polling
                                     AJAX, Multipart AJAX, Iframes, but looks just like
var a = new io.Socket();             WebSocket.
a.send(‘test’);
 .on(‘connect’, function(){
    alert(‘connected’);
                                 •   Solves the differences between browsers. Works
 })                                  on IE5.5+, Safari 3+, Chrome, FF3+, Opera10,
 .on(‘message’, function(msg){       iPhone, iPad, Android, WebOS.
   alert(msg);
 });
 .on(‘disconnect’, function(){   •   Adds new features. Disconnection support is
     alert(‘disconnected’);          more reliable than WebSocket. Message buffering.
 });

                                 •   Easy to extend without altering any natives. 10kb
                                     compressed.

                                 •   The jQuery of WebSocket
Socket.IO
•   http://socket.io / http://github.com/learnboost/socket.io-node

•   Multiple applications deployed to production

•   ~1000 github followers (socket.io and socket.io-node)

•   4 of the 7 Node.JS 48-hour coding competition winners use socket.io.

•   Rocketpack.fi used socket.io+node.js to build an infrastructure that scales
    to 100.000 simultaneous connections for a multiplayer gaming platform
    (with a Scala backend for message passing and a sticky load balancer)

•   Swarmation.com handles an average of 100 persistent connections while
    working on every browser.
New in 0.6

•   Over 20 bugfixes.

•   Bullet-proof disconnection support in the client
    (eg: internet disconnection)

•   Works behind all proxies

•   Works for cross-domain connections

•   Easier to deploy
What’s next?
•   New APIs to ease the streaming of *many* subsequent
    messages (making it easier to develop multiplayer games
    for example)

•   SSL support for all transports (wss and https)

•   Distributed automated testing

•   NodeStream, a layer on top of Socket.IO and the Express
    node.js web framework for creating realtime web apps
    with hardly any coding. Will be announced at JSConf.eu 10.
Questions?
1 of 13

Recommended

Socket.io (part 1) by
Socket.io (part 1)Socket.io (part 1)
Socket.io (part 1)Andrea Tarquini
2.3K views30 slides
Socket.IO by
Socket.IOSocket.IO
Socket.IOArnout Kazemier
7K views42 slides
Real Time Communication using Node.js and Socket.io by
Real Time Communication using Node.js and Socket.ioReal Time Communication using Node.js and Socket.io
Real Time Communication using Node.js and Socket.ioMindfire Solutions
5.6K views16 slides
Going realtime with Socket.IO by
Going realtime with Socket.IOGoing realtime with Socket.IO
Going realtime with Socket.IOChristian Joudrey
7.6K views22 slides
Going real time with Socket.io by
Going real time with Socket.ioGoing real time with Socket.io
Going real time with Socket.ioArnout Kazemier
11.5K views48 slides
Socket.IO - Alternative Ways for Real-time Application by
Socket.IO - Alternative Ways for Real-time ApplicationSocket.IO - Alternative Ways for Real-time Application
Socket.IO - Alternative Ways for Real-time ApplicationVorakamol Choonhasakulchok
4.8K views25 slides

More Related Content

What's hot

Node worshop Realtime - Socket.io by
Node worshop Realtime - Socket.ioNode worshop Realtime - Socket.io
Node worshop Realtime - Socket.ioCaesar Chi
2.3K views59 slides
NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014 by
NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014
NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014Stéphane ESCANDELL
4.7K views27 slides
Socket.IO by
Socket.IOSocket.IO
Socket.IODavide Pedranz
2K views11 slides
Ember and WebSockets by
Ember and WebSocketsEmber and WebSockets
Ember and WebSocketsSteve Kinney
1.8K views33 slides
Dancing with websocket by
Dancing with websocketDancing with websocket
Dancing with websocketDamien Krotkine
3.8K views28 slides
Web3j 2.0 Update by
Web3j 2.0 UpdateWeb3j 2.0 Update
Web3j 2.0 UpdateConor Svensson
971 views9 slides

What's hot(20)

Node worshop Realtime - Socket.io by Caesar Chi
Node worshop Realtime - Socket.ioNode worshop Realtime - Socket.io
Node worshop Realtime - Socket.io
Caesar Chi2.3K views
NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014 by Stéphane ESCANDELL
NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014
NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014
Stéphane ESCANDELL4.7K views
Ember and WebSockets by Steve Kinney
Ember and WebSocketsEmber and WebSockets
Ember and WebSockets
Steve Kinney1.8K views
Building Java and Android apps on the blockchain by Conor Svensson
Building Java and Android apps on the blockchain Building Java and Android apps on the blockchain
Building Java and Android apps on the blockchain
Conor Svensson21.7K views
Introduction to Nodejs by Gabriele Lana
Introduction to NodejsIntroduction to Nodejs
Introduction to Nodejs
Gabriele Lana17.6K views
Asynchronous PHP and Real-time Messaging by Steve Rhoades
Asynchronous PHP and Real-time MessagingAsynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time Messaging
Steve Rhoades19.2K views
Avoiding callback hell in Node js using promises by Ankit Agarwal
Avoiding callback hell in Node js using promisesAvoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promises
Ankit Agarwal5.9K views
Perl: Coro asynchronous by Shmuel Fomberg
Perl: Coro asynchronous Perl: Coro asynchronous
Perl: Coro asynchronous
Shmuel Fomberg3.3K views
Non-blocking I/O, Event loops and node.js by Marcus Frödin
Non-blocking I/O, Event loops and node.jsNon-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.js
Marcus Frödin22.8K views
What Is Async, How Does It Work, And When Should I Use It? by emptysquare
What Is Async, How Does It Work, And When Should I Use It?What Is Async, How Does It Work, And When Should I Use It?
What Is Async, How Does It Work, And When Should I Use It?
emptysquare1.9K views
CP3108B (Mozilla) Sharing Session on Add-on SDK by Mifeng
CP3108B (Mozilla) Sharing Session on Add-on SDKCP3108B (Mozilla) Sharing Session on Add-on SDK
CP3108B (Mozilla) Sharing Session on Add-on SDK
Mifeng724 views
soft-shake.ch - Hands on Node.js by soft-shake.ch
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
soft-shake.ch2.3K views
RESTful API In Node Js using Express by Jeetendra singh
RESTful API In Node Js using Express RESTful API In Node Js using Express
RESTful API In Node Js using Express
Jeetendra singh360 views

Viewers also liked

Web in real time - technical project - socket.io by
Web in real time - technical project - socket.ioWeb in real time - technical project - socket.io
Web in real time - technical project - socket.ioThomas Ferney
775 views22 slides
Socket.io - Intro by
Socket.io - IntroSocket.io - Intro
Socket.io - IntroAntonio Kobashikawa Carrasco
942 views16 slides
Web socket with php v2 by
Web socket with php v2Web socket with php v2
Web socket with php v2Leonardo Rifeli
607 views26 slides
Node.js 淺談socket.io by
Node.js   淺談socket.ioNode.js   淺談socket.io
Node.js 淺談socket.ioSimon Su
4K views18 slides
Nodejs+socket ioを試す by
Nodejs+socket ioを試すNodejs+socket ioを試す
Nodejs+socket ioを試すuzundk
2.5K views17 slides
Real time web: is there a life without socket.io and node.js? by
Real time web: is there a life without socket.io and node.js?Real time web: is there a life without socket.io and node.js?
Real time web: is there a life without socket.io and node.js?Eduard Trayan
6.9K views54 slides

Viewers also liked(9)

Web in real time - technical project - socket.io by Thomas Ferney
Web in real time - technical project - socket.ioWeb in real time - technical project - socket.io
Web in real time - technical project - socket.io
Thomas Ferney775 views
Node.js 淺談socket.io by Simon Su
Node.js   淺談socket.ioNode.js   淺談socket.io
Node.js 淺談socket.io
Simon Su4K views
Nodejs+socket ioを試す by uzundk
Nodejs+socket ioを試すNodejs+socket ioを試す
Nodejs+socket ioを試す
uzundk2.5K views
Real time web: is there a life without socket.io and node.js? by Eduard Trayan
Real time web: is there a life without socket.io and node.js?Real time web: is there a life without socket.io and node.js?
Real time web: is there a life without socket.io and node.js?
Eduard Trayan6.9K views
TDC2016POA | Trilha Web - Realtime applications com Socket.io by tdc-globalcode
TDC2016POA | Trilha Web - Realtime applications com Socket.ioTDC2016POA | Trilha Web - Realtime applications com Socket.io
TDC2016POA | Trilha Web - Realtime applications com Socket.io
tdc-globalcode300 views
Real-time Web Application with Socket.IO, Node.js, and Redis by York Tsai
Real-time Web Application with Socket.IO, Node.js, and RedisReal-time Web Application with Socket.IO, Node.js, and Redis
Real-time Web Application with Socket.IO, Node.js, and Redis
York Tsai33.4K views
NodeJS基礎教學&簡介 by GO LL
NodeJS基礎教學&簡介NodeJS基礎教學&簡介
NodeJS基礎教學&簡介
GO LL41K views

Similar to Socket.io

Nodejs and WebSockets by
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSocketsGonzalo Ayuso
13.5K views35 slides
Introduction to Vert.x by
Introduction to Vert.xIntroduction to Vert.x
Introduction to Vert.xYiguang Hu
3.5K views30 slides
Node.js - A practical introduction (v2) by
Node.js  - A practical introduction (v2)Node.js  - A practical introduction (v2)
Node.js - A practical introduction (v2)Felix Geisendörfer
4.7K views77 slides
Nodejs a-practical-introduction-oredev by
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevFelix Geisendörfer
2.9K views59 slides
GWT Web Socket and data serialization by
GWT Web Socket and data serializationGWT Web Socket and data serialization
GWT Web Socket and data serializationGWTcon
6.5K views27 slides
introduction to node.js by
introduction to node.jsintroduction to node.js
introduction to node.jsorkaplan
3.7K views30 slides

Similar to Socket.io(20)

Nodejs and WebSockets by Gonzalo Ayuso
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSockets
Gonzalo Ayuso13.5K views
Introduction to Vert.x by Yiguang Hu
Introduction to Vert.xIntroduction to Vert.x
Introduction to Vert.x
Yiguang Hu3.5K views
GWT Web Socket and data serialization by GWTcon
GWT Web Socket and data serializationGWT Web Socket and data serialization
GWT Web Socket and data serialization
GWTcon 6.5K views
introduction to node.js by orkaplan
introduction to node.jsintroduction to node.js
introduction to node.js
orkaplan3.7K views
Event-driven IO server-side JavaScript environment based on V8 Engine by Ricardo Silva
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 Engine
Ricardo Silva4.1K views
Introduction to Node.js by Richard Lee
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Richard Lee2K views
Writing robust Node.js applications by Tom Croucher
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
Tom Croucher15.6K views
Velocity EU 2014 — Offline-first web apps by andrewsmatt
Velocity EU 2014 — Offline-first web appsVelocity EU 2014 — Offline-first web apps
Velocity EU 2014 — Offline-first web apps
andrewsmatt3.9K views
Original slides from Ryan Dahl's NodeJs intro talk by Aarti Parikh
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talk
Aarti Parikh2.1K views
Node.js 101 with Rami Sayar by FITC
Node.js 101 with Rami SayarNode.js 101 with Rami Sayar
Node.js 101 with Rami Sayar
FITC6.1K views
Lecture 6 Web Sockets by Fahad Golra
Lecture 6   Web SocketsLecture 6   Web Sockets
Lecture 6 Web Sockets
Fahad Golra1.1K views
Websockets - DevFestX May 19, 2012 by Sameer Segal
Websockets - DevFestX May 19, 2012Websockets - DevFestX May 19, 2012
Websockets - DevFestX May 19, 2012
Sameer Segal978 views
Monitoring OSGi Applications with the Web Console by Adobe
Monitoring OSGi Applications with the Web ConsoleMonitoring OSGi Applications with the Web Console
Monitoring OSGi Applications with the Web Console
Adobe2.6K views
Monitoring OSGi Applications with the Web Console - Carsten Ziegeler by mfrancis
Monitoring OSGi Applications with the Web Console - Carsten ZiegelerMonitoring OSGi Applications with the Web Console - Carsten Ziegeler
Monitoring OSGi Applications with the Web Console - Carsten Ziegeler
mfrancis1.7K views

More from Timothy Fitz

Good hypothesis testing is surprising! by
Good hypothesis testing is surprising!Good hypothesis testing is surprising!
Good hypothesis testing is surprising!Timothy Fitz
1K views26 slides
Continuous Deployment: Beyond Continuous Delivery by
Continuous Deployment: Beyond Continuous DeliveryContinuous Deployment: Beyond Continuous Delivery
Continuous Deployment: Beyond Continuous DeliveryTimothy Fitz
2.8K views95 slides
Gdc 2010 architecture final slideshare edition by
Gdc 2010 architecture final slideshare editionGdc 2010 architecture final slideshare edition
Gdc 2010 architecture final slideshare editionTimothy Fitz
697 views27 slides
Scaling Up Continuous Deployment by
Scaling Up Continuous DeploymentScaling Up Continuous Deployment
Scaling Up Continuous DeploymentTimothy Fitz
1.5K views20 slides
The Hard Problems of Continuous Deployment by
The Hard Problems of Continuous DeploymentThe Hard Problems of Continuous Deployment
The Hard Problems of Continuous DeploymentTimothy Fitz
3.6K views36 slides
Realtime web2012 by
Realtime web2012Realtime web2012
Realtime web2012Timothy Fitz
2K views35 slides

More from Timothy Fitz(12)

Good hypothesis testing is surprising! by Timothy Fitz
Good hypothesis testing is surprising!Good hypothesis testing is surprising!
Good hypothesis testing is surprising!
Timothy Fitz1K views
Continuous Deployment: Beyond Continuous Delivery by Timothy Fitz
Continuous Deployment: Beyond Continuous DeliveryContinuous Deployment: Beyond Continuous Delivery
Continuous Deployment: Beyond Continuous Delivery
Timothy Fitz2.8K views
Gdc 2010 architecture final slideshare edition by Timothy Fitz
Gdc 2010 architecture final slideshare editionGdc 2010 architecture final slideshare edition
Gdc 2010 architecture final slideshare edition
Timothy Fitz697 views
Scaling Up Continuous Deployment by Timothy Fitz
Scaling Up Continuous DeploymentScaling Up Continuous Deployment
Scaling Up Continuous Deployment
Timothy Fitz1.5K views
The Hard Problems of Continuous Deployment by Timothy Fitz
The Hard Problems of Continuous DeploymentThe Hard Problems of Continuous Deployment
The Hard Problems of Continuous Deployment
Timothy Fitz3.6K views
Continuous Deployment by Timothy Fitz
Continuous DeploymentContinuous Deployment
Continuous Deployment
Timothy Fitz1.9K views
Continuous Deployment by Timothy Fitz
Continuous DeploymentContinuous Deployment
Continuous Deployment
Timothy Fitz838 views
Continuous Deployment by Timothy Fitz
Continuous DeploymentContinuous Deployment
Continuous Deployment
Timothy Fitz2.8K views
Just In Time Scalability Agile Methods To Support Massive Growth Presentation by Timothy Fitz
Just In Time Scalability  Agile Methods To Support Massive Growth PresentationJust In Time Scalability  Agile Methods To Support Massive Growth Presentation
Just In Time Scalability Agile Methods To Support Massive Growth Presentation
Timothy Fitz1.3K views

Socket.io

  • 2. WebSocket • Ideal transport for realtime web applications • TCP for the web • Bi-directional full-duplex communication • Firefox 4 (beta), Google Chrome 4, Safari 5 • Draft, evolving protocol under constant revision/changes. http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol
  • 3. WebSocket is simple • Conceived with the idea of simplicity for the client-side developer and the server implementor. • The Socket.IO Node.JS WebSocket server is ~130 LOC • Yes, you can implement a scalable HTTP 1.1 server with WebSocket support in 130 LOC in JavaScript.
  • 4. WebSocket is simple var a = new WebSocket(‘ws://localhost’); a.onopen = function(){ alert(‘connected’); } a.onmessage = function(ev){ alert(ev.data); } a.onclose = function(){ alert(‘disconnected’); }
  • 5. WebSocket AJAX var a = new WebSocket(‘ws://localhost/w’); var a = new XMLHttpRequest(); a.onopen = function(){ a.onreadystatechange = function(){ alert(‘connected’); if (this.readyState == 4){ a.send(‘hello there’); alert(this.responseText); } } a.onmessage = function(ev){ }); alert(ev.data); a.open(‘GET’, ‘/some/url’); } a.send(); a.onclose = function(){ alert(‘disconnected’); }
  • 6. WebSocket AJAX var a = new WebSocket(‘ws://localhost/w’); var a = new XMLHttpRequest(); a.onopen = function(){ a.onreadystatechange = function(){ alert(‘connected’); if (this.readyState == 4){ a.send(‘hello there’); alert(this.responseText); } } a.onmessage = function(ev){ }); alert(ev.data); a.open(‘GET’, ‘/some/url’); } a.send(); a.onclose = function(){ alert(‘disconnected’); } • Connection stays open and messages are sent • Connection opens, headers are sent, response is emitted, connection is closed. bi-directionally. • Sends raw data from one point to the other, • GET, POST, PUT, DELETE,PATCH HTTP commands. doesn’t know any commands • Ideal for realtime interactions • Ideal for traditional interactions • Limited browser support. • Limited browser support
  • 7. How about cross browser support? To illustrate, let’s look at how people are using AJAX today
  • 8. How about cross browser support? jQuery • API on top of XMLHTTPRequest $.ajax({ • Solves the differences between browsers, url: ‘/some/url’, (implements MSXML ActiveX object for IE6) complete: function(data){ // do something and works on almost every user agent. } }) • Makes it even easier to write async requests • Adds *new features* that the standard doesn’t support (timeouts, caching, filters, etc)
  • 9. How about cross browser support? Socket.IO • API on top of WebSocket, Flash, Long Polling AJAX, Multipart AJAX, Iframes, but looks just like var a = new io.Socket(); WebSocket. a.send(‘test’); .on(‘connect’, function(){ alert(‘connected’); • Solves the differences between browsers. Works }) on IE5.5+, Safari 3+, Chrome, FF3+, Opera10, .on(‘message’, function(msg){ iPhone, iPad, Android, WebOS. alert(msg); }); .on(‘disconnect’, function(){ • Adds new features. Disconnection support is alert(‘disconnected’); more reliable than WebSocket. Message buffering. }); • Easy to extend without altering any natives. 10kb compressed. • The jQuery of WebSocket
  • 10. Socket.IO • http://socket.io / http://github.com/learnboost/socket.io-node • Multiple applications deployed to production • ~1000 github followers (socket.io and socket.io-node) • 4 of the 7 Node.JS 48-hour coding competition winners use socket.io. • Rocketpack.fi used socket.io+node.js to build an infrastructure that scales to 100.000 simultaneous connections for a multiplayer gaming platform (with a Scala backend for message passing and a sticky load balancer) • Swarmation.com handles an average of 100 persistent connections while working on every browser.
  • 11. New in 0.6 • Over 20 bugfixes. • Bullet-proof disconnection support in the client (eg: internet disconnection) • Works behind all proxies • Works for cross-domain connections • Easier to deploy
  • 12. What’s next? • New APIs to ease the streaming of *many* subsequent messages (making it easier to develop multiplayer games for example) • SSL support for all transports (wss and https) • Distributed automated testing • NodeStream, a layer on top of Socket.IO and the Express node.js web framework for creating realtime web apps with hardly any coding. Will be announced at JSConf.eu 10.

Editor's Notes