SlideShare a Scribd company logo
1 of 21
INTRODUCTION TO
       WEBSOCKETS
           jgourgoutis@linkedin.com


   WebSockets are a new way to connect
 clients and servers with efficient two-way
communication that allows us to build true
      desktop-style web applications!
Legacy Web
HTTP Protocol
• High Overhead (request & response
  headers, cookies, etc.)
• “Half-duplex” connection
  (request/response)
Current Workarounds
• AJAX/XHR
  – Content can update w/o full page refresh
  – User-perceived low latency
  – Faux real-time via polling/long-polling
• Comet
  – No standard specification
  – Very complex to implement
HTML5 WebSockets
WebSocket Advantages!
•   Full-duplex, low overhead
•   Direct connection between client & server
•   Same ports as HTTP/HTTPS
•   Based on Web Standards (W3C & IETF)
•   Unlike XHR, it works cross-domain!
More Details
• “ws” and “wss” protocols
• Two-part “handshake”: HTTP upgrade to WS
  in request header
WebSocket API
varws = new WebSocket(url);
ws.onopen = function (evt) { /* connection
  open */ };
ws.onmessage= function (evt) { /* received
  message */ console.dir(evt.data); };
ws.onclose= function(evt){ /* connection
  closed */ };
WebSocket API (ctd)
// Send a message
ws.send(“Do you like the scary clowns?!?”);

// Close the connection
ws.close();
WebSockets Browser Support
Server Events
Not Like WebSockets!
•   Not two-way, just push from server
•   Uses plain-ol’ HTTP
•   Different message transport mechanism
•   Same-origin policy applies.
EventSource API
vares = new EventSource(url);
es.readyState property
0 = connecting,1 = open, 2 = closed
es.close() closes the connection
EventSource Events
es.onopen = function(evt){};
es.onmessage = function(evt){};
es.onerror = function(evt){};
es.addEventListener();

Data object: evt.data
Sending Messages
• MIME type = text/event-stream
• Plain-text format
• id: message; id defaults to “data” if not
  specified
• New lines (n) are significant
EventSource Browser Support
SEXY
DEMO
TIME!
I built a web chat application using WebSocket and EventSource.
Oh, and some Node.js and Socket.io, too.
http://jgourgou-mn.linkedin.biz:8080/

SUPER-AWESOME WEBSOCKET
CHAT DEMO
Take-Aways
• Socket.io is to WebSockets as Jquery is to
  DOM
• Socket.io documentation sucks.
• Web examples for Socket.io suck.
• Node.js is weirdly cool, and overwhelming in
  a Java sort of way.
Resources/Further Reading
• http://www.slideshare.net/pmoskovi/building-living-
  web-applications-with-html5-websockets
• http://howtonode.org/websockets-socketio
• https://github.com/LearnBoost/socket.io
• http://www.websocket.org/
• http://www.nczonline.net/blog/2010/10/19/introducti
  on-to-server-sent-events/
• https://github.com/remy/eventsource-h5d
• http://www.html5rocks.com/en/tutorials/eventsourc
  e/basics/
• http://html5doctor.com/server-sent-events/
Questions?

More Related Content

What's hot

Link Header-based Invalidation of Caches
Link Header-based Invalidation of CachesLink Header-based Invalidation of Caches
Link Header-based Invalidation of Cachesmikekelly
 
Server system architecture
Server system architectureServer system architecture
Server system architectureFaiza Hafeez
 
Web Socket
Web SocketWeb Socket
Web SocketJack Bui
 
REST Easy with AngularJS - ng-grid CRUD EXAMPLE
REST Easy with AngularJS - ng-grid CRUD EXAMPLEREST Easy with AngularJS - ng-grid CRUD EXAMPLE
REST Easy with AngularJS - ng-grid CRUD EXAMPLEreneechemel
 
Applying microservices principles to front end
Applying microservices principles to front endApplying microservices principles to front end
Applying microservices principles to front endAhmed Elharouny
 
Multi-Process JavaScript Architectures
Multi-Process JavaScript ArchitecturesMulti-Process JavaScript Architectures
Multi-Process JavaScript ArchitecturesMark Trostler
 
Web service testing_final.pptx
Web service testing_final.pptxWeb service testing_final.pptx
Web service testing_final.pptxvodqancr
 
Realtime web application with java
Realtime web application with javaRealtime web application with java
Realtime web application with javaJeongHun Byeon
 
Building Websocket Applications with GlassFish and Grizzly
Building Websocket Applications with GlassFish and GrizzlyBuilding Websocket Applications with GlassFish and Grizzly
Building Websocket Applications with GlassFish and GrizzlyJustin Lee
 
Advance java session 4
Advance java session 4Advance java session 4
Advance java session 4Smita B Kumar
 
Node Session - 3
Node Session - 3Node Session - 3
Node Session - 3Bhavin Shah
 
Developing Revolutionary Web Applications using Comet and Ajax Push
Developing Revolutionary Web Applications using Comet and Ajax PushDeveloping Revolutionary Web Applications using Comet and Ajax Push
Developing Revolutionary Web Applications using Comet and Ajax PushDoris Chen
 

What's hot (20)

Link Header-based Invalidation of Caches
Link Header-based Invalidation of CachesLink Header-based Invalidation of Caches
Link Header-based Invalidation of Caches
 
Server system architecture
Server system architectureServer system architecture
Server system architecture
 
AJAX - An introduction
AJAX - An introductionAJAX - An introduction
AJAX - An introduction
 
HTML5 - An introduction
HTML5 - An introductionHTML5 - An introduction
HTML5 - An introduction
 
Web Socket
Web SocketWeb Socket
Web Socket
 
Angularjs & REST
Angularjs & RESTAngularjs & REST
Angularjs & REST
 
REST Easy with AngularJS - ng-grid CRUD EXAMPLE
REST Easy with AngularJS - ng-grid CRUD EXAMPLEREST Easy with AngularJS - ng-grid CRUD EXAMPLE
REST Easy with AngularJS - ng-grid CRUD EXAMPLE
 
Applying microservices principles to front end
Applying microservices principles to front endApplying microservices principles to front end
Applying microservices principles to front end
 
Soap Vs Rest
Soap Vs RestSoap Vs Rest
Soap Vs Rest
 
Multi-Process JavaScript Architectures
Multi-Process JavaScript ArchitecturesMulti-Process JavaScript Architectures
Multi-Process JavaScript Architectures
 
SOAP vs REST
SOAP vs RESTSOAP vs REST
SOAP vs REST
 
Web service testing_final.pptx
Web service testing_final.pptxWeb service testing_final.pptx
Web service testing_final.pptx
 
AJAX
AJAXAJAX
AJAX
 
Realtime web application with java
Realtime web application with javaRealtime web application with java
Realtime web application with java
 
Jquery Ajax
Jquery AjaxJquery Ajax
Jquery Ajax
 
Building Websocket Applications with GlassFish and Grizzly
Building Websocket Applications with GlassFish and GrizzlyBuilding Websocket Applications with GlassFish and Grizzly
Building Websocket Applications with GlassFish and Grizzly
 
Advance java session 4
Advance java session 4Advance java session 4
Advance java session 4
 
Node Session - 3
Node Session - 3Node Session - 3
Node Session - 3
 
Node js
Node jsNode js
Node js
 
Developing Revolutionary Web Applications using Comet and Ajax Push
Developing Revolutionary Web Applications using Comet and Ajax PushDeveloping Revolutionary Web Applications using Comet and Ajax Push
Developing Revolutionary Web Applications using Comet and Ajax Push
 

Similar to Intro to Web Sockets

Server-Side Programming Primer
Server-Side Programming PrimerServer-Side Programming Primer
Server-Side Programming PrimerIvano Malavolta
 
Dev con kolkata 2012 websockets
Dev con kolkata 2012   websocketsDev con kolkata 2012   websockets
Dev con kolkata 2012 websocketsSANKARSAN BOSE
 
Web Real-time Communications
Web Real-time CommunicationsWeb Real-time Communications
Web Real-time CommunicationsAlexei Skachykhin
 
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 WebPeter Lubbers
 
Synapseindia dot net development web applications with ajax
Synapseindia dot net development  web applications with ajaxSynapseindia dot net development  web applications with ajax
Synapseindia dot net development web applications with ajaxSynapseindiappsdevelopment
 
Web Technologies - forms and actions
Web Technologies -  forms and actionsWeb Technologies -  forms and actions
Web Technologies - forms and actionsAren Zomorodian
 
Decoding real time web communication
Decoding real time web communicationDecoding real time web communication
Decoding real time web communicationAMiT JAiN
 
HTML5/JavaScript Communication APIs - DPC 2014
HTML5/JavaScript Communication APIs - DPC 2014HTML5/JavaScript Communication APIs - DPC 2014
HTML5/JavaScript Communication APIs - DPC 2014Christian Wenz
 
Real-Time with Flowdock
Real-Time with FlowdockReal-Time with Flowdock
Real-Time with FlowdockFlowdock
 
Dynamic content generation
Dynamic content generationDynamic content generation
Dynamic content generationEleonora Ciceri
 
4Developers 2018: Real-time capabilities in ASP.NET Core web applications (To...
4Developers 2018: Real-time capabilities in ASP.NET Core web applications (To...4Developers 2018: Real-time capabilities in ASP.NET Core web applications (To...
4Developers 2018: Real-time capabilities in ASP.NET Core web applications (To...PROIDEA
 
Get Real: Adventures in realtime web apps
Get Real: Adventures in realtime web appsGet Real: Adventures in realtime web apps
Get Real: Adventures in realtime web appsdaviddemello
 
Top 10 HTML5 Features for Oracle Cloud Developers
Top 10 HTML5 Features for Oracle Cloud DevelopersTop 10 HTML5 Features for Oracle Cloud Developers
Top 10 HTML5 Features for Oracle Cloud DevelopersBrian Huff
 
Ajax tutorial by bally chohan
Ajax tutorial by bally chohanAjax tutorial by bally chohan
Ajax tutorial by bally chohanWebVineet
 

Similar to Intro to Web Sockets (20)

Building real-time-collaborative-web-applications
Building real-time-collaborative-web-applicationsBuilding real-time-collaborative-web-applications
Building real-time-collaborative-web-applications
 
Websocket
WebsocketWebsocket
Websocket
 
Server-Side Programming Primer
Server-Side Programming PrimerServer-Side Programming Primer
Server-Side Programming Primer
 
AJAX.pptx
AJAX.pptxAJAX.pptx
AJAX.pptx
 
Ajax
AjaxAjax
Ajax
 
Dev con kolkata 2012 websockets
Dev con kolkata 2012   websocketsDev con kolkata 2012   websockets
Dev con kolkata 2012 websockets
 
Socket.io
Socket.ioSocket.io
Socket.io
 
Web Real-time Communications
Web Real-time CommunicationsWeb Real-time Communications
Web Real-time Communications
 
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
 
Synapseindia dot net development web applications with ajax
Synapseindia dot net development  web applications with ajaxSynapseindia dot net development  web applications with ajax
Synapseindia dot net development web applications with ajax
 
08 ajax
08 ajax08 ajax
08 ajax
 
Web Technologies - forms and actions
Web Technologies -  forms and actionsWeb Technologies -  forms and actions
Web Technologies - forms and actions
 
Decoding real time web communication
Decoding real time web communicationDecoding real time web communication
Decoding real time web communication
 
HTML5/JavaScript Communication APIs - DPC 2014
HTML5/JavaScript Communication APIs - DPC 2014HTML5/JavaScript Communication APIs - DPC 2014
HTML5/JavaScript Communication APIs - DPC 2014
 
Real-Time with Flowdock
Real-Time with FlowdockReal-Time with Flowdock
Real-Time with Flowdock
 
Dynamic content generation
Dynamic content generationDynamic content generation
Dynamic content generation
 
4Developers 2018: Real-time capabilities in ASP.NET Core web applications (To...
4Developers 2018: Real-time capabilities in ASP.NET Core web applications (To...4Developers 2018: Real-time capabilities in ASP.NET Core web applications (To...
4Developers 2018: Real-time capabilities in ASP.NET Core web applications (To...
 
Get Real: Adventures in realtime web apps
Get Real: Adventures in realtime web appsGet Real: Adventures in realtime web apps
Get Real: Adventures in realtime web apps
 
Top 10 HTML5 Features for Oracle Cloud Developers
Top 10 HTML5 Features for Oracle Cloud DevelopersTop 10 HTML5 Features for Oracle Cloud Developers
Top 10 HTML5 Features for Oracle Cloud Developers
 
Ajax tutorial by bally chohan
Ajax tutorial by bally chohanAjax tutorial by bally chohan
Ajax tutorial by bally chohan
 

Recently uploaded

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 

Recently uploaded (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

Intro to Web Sockets

  • 1. INTRODUCTION TO WEBSOCKETS jgourgoutis@linkedin.com WebSockets are a new way to connect clients and servers with efficient two-way communication that allows us to build true desktop-style web applications!
  • 3. HTTP Protocol • High Overhead (request & response headers, cookies, etc.) • “Half-duplex” connection (request/response)
  • 4. Current Workarounds • AJAX/XHR – Content can update w/o full page refresh – User-perceived low latency – Faux real-time via polling/long-polling • Comet – No standard specification – Very complex to implement
  • 6. WebSocket Advantages! • Full-duplex, low overhead • Direct connection between client & server • Same ports as HTTP/HTTPS • Based on Web Standards (W3C & IETF) • Unlike XHR, it works cross-domain!
  • 7. More Details • “ws” and “wss” protocols • Two-part “handshake”: HTTP upgrade to WS in request header
  • 8. WebSocket API varws = new WebSocket(url); ws.onopen = function (evt) { /* connection open */ }; ws.onmessage= function (evt) { /* received message */ console.dir(evt.data); }; ws.onclose= function(evt){ /* connection closed */ };
  • 9. WebSocket API (ctd) // Send a message ws.send(“Do you like the scary clowns?!?”); // Close the connection ws.close();
  • 12. Not Like WebSockets! • Not two-way, just push from server • Uses plain-ol’ HTTP • Different message transport mechanism • Same-origin policy applies.
  • 13. EventSource API vares = new EventSource(url); es.readyState property 0 = connecting,1 = open, 2 = closed es.close() closes the connection
  • 14. EventSource Events es.onopen = function(evt){}; es.onmessage = function(evt){}; es.onerror = function(evt){}; es.addEventListener(); Data object: evt.data
  • 15. Sending Messages • MIME type = text/event-stream • Plain-text format • id: message; id defaults to “data” if not specified • New lines (n) are significant
  • 18. I built a web chat application using WebSocket and EventSource. Oh, and some Node.js and Socket.io, too. http://jgourgou-mn.linkedin.biz:8080/ SUPER-AWESOME WEBSOCKET CHAT DEMO
  • 19. Take-Aways • Socket.io is to WebSockets as Jquery is to DOM • Socket.io documentation sucks. • Web examples for Socket.io suck. • Node.js is weirdly cool, and overwhelming in a Java sort of way.
  • 20. Resources/Further Reading • http://www.slideshare.net/pmoskovi/building-living- web-applications-with-html5-websockets • http://howtonode.org/websockets-socketio • https://github.com/LearnBoost/socket.io • http://www.websocket.org/ • http://www.nczonline.net/blog/2010/10/19/introducti on-to-server-sent-events/ • https://github.com/remy/eventsource-h5d • http://www.html5rocks.com/en/tutorials/eventsourc e/basics/ • http://html5doctor.com/server-sent-events/

Editor's Notes

  1. “Building Living Web Applications with HTML5 Websockets” presentation from Peter Moskovits @Kaazing
  2. “Half-duplex” is analogous to picking up a phone, dialing a number, waiting for the other end to pick up, asking a question, getting a response, hanging up, and then repeating for the next question – instead of having a fluid, 10-minute conversation.
  3. A type-ahead widget sending the letter “a” back to the server via XHR incurs a cost of 788  bytes  in the header for the 1  byte of the character