SlideShare ist ein Scribd-Unternehmen logo
1 von 13
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?

Weitere ähnliche Inhalte

Was ist angesagt?

Node worshop Realtime - Socket.io
Node worshop Realtime - Socket.ioNode worshop Realtime - Socket.io
Node worshop Realtime - Socket.ioCaesar Chi
 
NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014
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
 
Ember and WebSockets
Ember and WebSocketsEmber and WebSockets
Ember and WebSocketsSteve Kinney
 
Building Java and Android apps on the blockchain
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 Svensson
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to NodejsGabriele Lana
 
Asynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time MessagingAsynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time MessagingSteve Rhoades
 
Avoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promisesAvoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promisesAnkit Agarwal
 
Perl: Coro asynchronous
Perl: Coro asynchronous Perl: Coro asynchronous
Perl: Coro asynchronous Shmuel Fomberg
 
Non-blocking I/O, Event loops and node.js
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.jsMarcus Frödin
 
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?
What Is Async, How Does It Work, And When Should I Use It?emptysquare
 
CP3108B (Mozilla) Sharing Session on Add-on SDK
CP3108B (Mozilla) Sharing Session on Add-on SDKCP3108B (Mozilla) Sharing Session on Add-on SDK
CP3108B (Mozilla) Sharing Session on Add-on SDKMifeng
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch
 
RESTful API In Node Js using Express
RESTful API In Node Js using Express RESTful API In Node Js using Express
RESTful API In Node Js using Express Jeetendra singh
 

Was ist angesagt? (20)

Node worshop Realtime - Socket.io
Node worshop Realtime - Socket.ioNode worshop Realtime - Socket.io
Node worshop Realtime - Socket.io
 
NodeJS & Socket IO on Microsoft Azure Cloud Web Sites - DWX 2014
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
 
Socket.IO
Socket.IOSocket.IO
Socket.IO
 
Ember and WebSockets
Ember and WebSocketsEmber and WebSockets
Ember and WebSockets
 
Dancing with websocket
Dancing with websocketDancing with websocket
Dancing with websocket
 
Web3j 2.0 Update
Web3j 2.0 UpdateWeb3j 2.0 Update
Web3j 2.0 Update
 
web3j Overview
web3j Overviewweb3j Overview
web3j Overview
 
Building Java and Android apps on the blockchain
Building Java and Android apps on the blockchain Building Java and Android apps on the blockchain
Building Java and Android apps on the blockchain
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to Nodejs
 
aiohttp intro
aiohttp introaiohttp intro
aiohttp intro
 
Asynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time MessagingAsynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time Messaging
 
WebSockets with PHP: Mission impossible
WebSockets with PHP: Mission impossibleWebSockets with PHP: Mission impossible
WebSockets with PHP: Mission impossible
 
Avoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promisesAvoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promises
 
Node.js - A Quick Tour
Node.js - A Quick TourNode.js - A Quick Tour
Node.js - A Quick Tour
 
Perl: Coro asynchronous
Perl: Coro asynchronous Perl: Coro asynchronous
Perl: Coro asynchronous
 
Non-blocking I/O, Event loops and node.js
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
 
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?
What Is Async, How Does It Work, And When Should I Use It?
 
CP3108B (Mozilla) Sharing Session on Add-on SDK
CP3108B (Mozilla) Sharing Session on Add-on SDKCP3108B (Mozilla) Sharing Session on Add-on SDK
CP3108B (Mozilla) Sharing Session on Add-on SDK
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
 
RESTful API In Node Js using Express
RESTful API In Node Js using Express RESTful API In Node Js using Express
RESTful API In Node Js using Express
 

Andere mochten auch

Web in real time - technical project - socket.io
Web in real time - technical project - socket.ioWeb in real time - technical project - socket.io
Web in real time - technical project - socket.ioThomas Ferney
 
Node.js 淺談socket.io
Node.js   淺談socket.ioNode.js   淺談socket.io
Node.js 淺談socket.ioSimon Su
 
Nodejs+socket ioを試す
Nodejs+socket ioを試すNodejs+socket ioを試す
Nodejs+socket ioを試すuzundk
 
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?
Real time web: is there a life without socket.io and node.js?Eduard Trayan
 
TDC2016POA | Trilha Web - Realtime applications com Socket.io
TDC2016POA | Trilha Web - Realtime applications com Socket.ioTDC2016POA | Trilha Web - Realtime applications com Socket.io
TDC2016POA | Trilha Web - Realtime applications com Socket.iotdc-globalcode
 
Real-time Web Application with Socket.IO, Node.js, and Redis
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 RedisYork Tsai
 
NodeJS基礎教學&簡介
NodeJS基礎教學&簡介NodeJS基礎教學&簡介
NodeJS基礎教學&簡介GO LL
 

Andere mochten auch (9)

Web in real time - technical project - socket.io
Web in real time - technical project - socket.ioWeb in real time - technical project - socket.io
Web in real time - technical project - socket.io
 
Socket.io - Intro
Socket.io - IntroSocket.io - Intro
Socket.io - Intro
 
Web socket with php v2
Web socket with php v2Web socket with php v2
Web socket with php v2
 
Node.js 淺談socket.io
Node.js   淺談socket.ioNode.js   淺談socket.io
Node.js 淺談socket.io
 
Nodejs+socket ioを試す
Nodejs+socket ioを試すNodejs+socket ioを試す
Nodejs+socket ioを試す
 
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?
Real time web: is there a life without socket.io and node.js?
 
TDC2016POA | Trilha Web - Realtime applications com Socket.io
TDC2016POA | Trilha Web - Realtime applications com Socket.ioTDC2016POA | Trilha Web - Realtime applications com Socket.io
TDC2016POA | Trilha Web - Realtime applications com Socket.io
 
Real-time Web Application with Socket.IO, Node.js, and Redis
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
 
NodeJS基礎教學&簡介
NodeJS基礎教學&簡介NodeJS基礎教學&簡介
NodeJS基礎教學&簡介
 

Ähnlich wie Socket.io

Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSocketsGonzalo Ayuso
 
Introduction to Vert.x
Introduction to Vert.xIntroduction to Vert.x
Introduction to Vert.xYiguang Hu
 
Node.js - A practical introduction (v2)
Node.js  - A practical introduction (v2)Node.js  - A practical introduction (v2)
Node.js - A practical introduction (v2)Felix Geisendörfer
 
Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevFelix Geisendörfer
 
GWT Web Socket and data serialization
GWT Web Socket and data serializationGWT Web Socket and data serialization
GWT Web Socket and data serializationGWTcon
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.jsorkaplan
 
Groovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentationGroovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentationStuart (Pid) Williams
 
Event-driven IO server-side JavaScript environment based on V8 Engine
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 EngineRicardo Silva
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsRichard Lee
 
Jugando con websockets en nodeJS
Jugando con websockets en nodeJSJugando con websockets en nodeJS
Jugando con websockets en nodeJSIsrael Gutiérrez
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applicationsTom Croucher
 
Velocity EU 2014 — Offline-first web apps
Velocity EU 2014 — Offline-first web appsVelocity EU 2014 — Offline-first web apps
Velocity EU 2014 — Offline-first web appsandrewsmatt
 
Original slides from Ryan Dahl's NodeJs intro talk
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 talkAarti Parikh
 
Node.js 101 with Rami Sayar
Node.js 101 with Rami SayarNode.js 101 with Rami Sayar
Node.js 101 with Rami SayarFITC
 
Lecture 6 Web Sockets
Lecture 6   Web SocketsLecture 6   Web Sockets
Lecture 6 Web SocketsFahad Golra
 
Websockets - DevFestX May 19, 2012
Websockets - DevFestX May 19, 2012Websockets - DevFestX May 19, 2012
Websockets - DevFestX May 19, 2012Sameer Segal
 
Monitoring OSGi Applications with the Web Console
Monitoring OSGi Applications with the Web ConsoleMonitoring OSGi Applications with the Web Console
Monitoring OSGi Applications with the Web ConsoleCarsten Ziegeler
 
Monitoring OSGi Applications with the Web Console - Carsten Ziegeler
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 Ziegelermfrancis
 

Ähnlich wie Socket.io (20)

Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSockets
 
Introduction to Vert.x
Introduction to Vert.xIntroduction to Vert.x
Introduction to Vert.x
 
Node.js - A practical introduction (v2)
Node.js  - A practical introduction (v2)Node.js  - A practical introduction (v2)
Node.js - A practical introduction (v2)
 
Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredev
 
GWT Web Socket and data serialization
GWT Web Socket and data serializationGWT Web Socket and data serialization
GWT Web Socket and data serialization
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Groovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentationGroovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentation
 
Event-driven IO server-side JavaScript environment based on V8 Engine
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
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Jugando con websockets en nodeJS
Jugando con websockets en nodeJSJugando con websockets en nodeJS
Jugando con websockets en nodeJS
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Velocity EU 2014 — Offline-first web apps
Velocity EU 2014 — Offline-first web appsVelocity EU 2014 — Offline-first web apps
Velocity EU 2014 — Offline-first web apps
 
Node.js on Azure
Node.js on AzureNode.js on Azure
Node.js on Azure
 
Original slides from Ryan Dahl's NodeJs intro talk
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
 
JS everywhere 2011
JS everywhere 2011JS everywhere 2011
JS everywhere 2011
 
Node.js 101 with Rami Sayar
Node.js 101 with Rami SayarNode.js 101 with Rami Sayar
Node.js 101 with Rami Sayar
 
Lecture 6 Web Sockets
Lecture 6   Web SocketsLecture 6   Web Sockets
Lecture 6 Web Sockets
 
Websockets - DevFestX May 19, 2012
Websockets - DevFestX May 19, 2012Websockets - DevFestX May 19, 2012
Websockets - DevFestX May 19, 2012
 
Monitoring OSGi Applications with the Web Console
Monitoring OSGi Applications with the Web ConsoleMonitoring OSGi Applications with the Web Console
Monitoring OSGi Applications with the Web Console
 
Monitoring OSGi Applications with the Web Console - Carsten Ziegeler
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
 

Mehr von Timothy Fitz

Good hypothesis testing is surprising!
Good hypothesis testing is surprising!Good hypothesis testing is surprising!
Good hypothesis testing is surprising!Timothy Fitz
 
Continuous Deployment: Beyond Continuous Delivery
Continuous Deployment: Beyond Continuous DeliveryContinuous Deployment: Beyond Continuous Delivery
Continuous Deployment: Beyond Continuous DeliveryTimothy Fitz
 
Gdc 2010 architecture final slideshare edition
Gdc 2010 architecture final slideshare editionGdc 2010 architecture final slideshare edition
Gdc 2010 architecture final slideshare editionTimothy Fitz
 
Scaling Up Continuous Deployment
Scaling Up Continuous DeploymentScaling Up Continuous Deployment
Scaling Up Continuous DeploymentTimothy Fitz
 
The Hard Problems of Continuous Deployment
The Hard Problems of Continuous DeploymentThe Hard Problems of Continuous Deployment
The Hard Problems of Continuous DeploymentTimothy Fitz
 
Continuous Deployment
Continuous DeploymentContinuous Deployment
Continuous DeploymentTimothy Fitz
 
Continuous Deployment
Continuous DeploymentContinuous Deployment
Continuous DeploymentTimothy Fitz
 
Continuous Deployment
Continuous DeploymentContinuous Deployment
Continuous DeploymentTimothy Fitz
 
Just In Time Scalability Agile Methods To Support Massive Growth Presentation
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 PresentationTimothy Fitz
 

Mehr von Timothy Fitz (12)

Good hypothesis testing is surprising!
Good hypothesis testing is surprising!Good hypothesis testing is surprising!
Good hypothesis testing is surprising!
 
Continuous Deployment: Beyond Continuous Delivery
Continuous Deployment: Beyond Continuous DeliveryContinuous Deployment: Beyond Continuous Delivery
Continuous Deployment: Beyond Continuous Delivery
 
Gdc 2010 architecture final slideshare edition
Gdc 2010 architecture final slideshare editionGdc 2010 architecture final slideshare edition
Gdc 2010 architecture final slideshare edition
 
Scaling Up Continuous Deployment
Scaling Up Continuous DeploymentScaling Up Continuous Deployment
Scaling Up Continuous Deployment
 
The Hard Problems of Continuous Deployment
The Hard Problems of Continuous DeploymentThe Hard Problems of Continuous Deployment
The Hard Problems of Continuous Deployment
 
Realtime web2012
Realtime web2012Realtime web2012
Realtime web2012
 
Continuous Deployment
Continuous DeploymentContinuous Deployment
Continuous Deployment
 
Continuous Deployment
Continuous DeploymentContinuous Deployment
Continuous Deployment
 
Shdh
ShdhShdh
Shdh
 
Shdh
ShdhShdh
Shdh
 
Continuous Deployment
Continuous DeploymentContinuous Deployment
Continuous Deployment
 
Just In Time Scalability Agile Methods To Support Massive Growth Presentation
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
 

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.

Hinweis der Redaktion