ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Node.js and
                           WebSockets
                         A (very) short introduction

                              Andreas Kompanez




Montag, 26. April 2010
Node.js
                         JavaScript Framework

                         Server-side

                         Uses V8

                         Evented and non-blocking

                         CommonJS

                         Uses ECMAScript 5


Montag, 26. April 2010
Node.js


                         Created by Ryan Dahl

                         ~8000 lines of C/C++ and 2000 lines
                         JavaScript

                         http://nodejs.org/




Montag, 26. April 2010
Evented?

                         Old (blocking) school:
                         <?php
                         $content = file_get_contents("/some/huge/file");
                         doThings($content); // Waiting, synchron
                         otherThing();




Montag, 26. April 2010
Evented?

                         Evented I/O
                         file.read("/some/huge/file", function(data) {
                             // called after data is read
                             doThings(data);
                         });
                         otherThing(); // execute immediately;




Montag, 26. April 2010
Benefits

                         Asynchronous programming

                         Event-loops instead of threads

                         Non-blocking

                         1 Thread (No context switching etc.)




Montag, 26. April 2010
CommonJS




Montag, 26. April 2010
CommonJS

                         A collection/library of standards

                           Modules

                           Binary

                           File system

                           and many more!



Montag, 26. April 2010
CommonJS Modules

                         There should be a function require

                         There should be a var called exports




Montag, 26. April 2010
Module Example
                         // math.js module
                         exports.multiply = function(a, b) {
                             return a * b;
                         }




                         // Some other file, using math.js
                         //
                         var math = require('./math');
                         var sys = require('sys');

                         sys.puts(math.multiply(12, 12));




Montag, 26. April 2010
Google V8 JavaScript
                      Engine
                         It¡¯s a VM!

                         Developed by Google

                         The team lead is Lars Bak (Sun¡¯s Java
                         VM & Smalltalk VM)

                         No JIT, compiled to Assembler



Montag, 26. April 2010
The 6+ lines http
                                server
                         // httpserver.js
                         // Usage: node httpserver.js
                         var sys = require("sys"),
                             http = require("http");

                         http.createServer(function(request, response) {
                           var headers = { "Content-Type": "text/plain" };
                           response.sendHeader(200, headers);
                           response.write("Hello, World!n");
                           response.close();
                         }).listen(8000);

                         sys.puts("Running at http://127.0.0.1:8000/");




Montag, 26. April 2010
WebSockets




Montag, 26. April 2010
WebSockets

                         A HTML5 standard

                         Allows bidirectional communications

                         Less overhead than HTTP/AJAX (less
                         headers)

                         Cross domain



Montag, 26. April 2010
Polling
                   Client    Mailman   Server




Montag, 26. April 2010
Bidirectional
                   Client   Telephone   Server




Montag, 26. April 2010
WS Communication
                              details
                         Handshake
                         GET /test HTTP/1.1              HTTP/1.1 101 Web Socket Protocol Handshake
                         Upgrade: WebSocket              Upgrade: WebSocket
                         Connection: Upgrade             Connection: Upgrade
                         Origin: http://localhost/test   Server: Resin/4.0.2
                         Host: localhost                 WebSocket-Location: ws://localhost/websocket
                         Content-Length: 0               WebSocket-Origin: http://localhost/test
                                                         Content-Length: 0
                                                         Date: Fri, 08 May 2009 09:51:31 GMT



                         Messages
                         x00hello, worldxff




Montag, 26. April 2010
WebSockets Client-
                                side
                   if (("WebSocket" in window)) {
                       var ws = new WebSocket("ws://localhost:8080/");

                         ws.onmessage = function(evt) {
                             // Receive
                         };
                         ws.onopen = function(evt) {
                             //
                             ws.send('Oh hai');
                         };
                         ws.onclose = function(evt) {
                             //
                         };
                         ws.onerror = function(evt) {
                             //
                         };
                         ws.close();
                   }

Montag, 26. April 2010
Demo!




Montag, 26. April 2010

More Related Content

What's hot (20)

MySQL Slow Query log Monitoring using Beats & ELK
MySQL Slow Query log Monitoring using Beats & ELKMySQL Slow Query log Monitoring using Beats & ELK
MySQL Slow Query log Monitoring using Beats & ELK
I Goo Lee
?
Crate Shared Nothing Web Backends - Web Backend Meetup May 2014
Crate Shared Nothing Web Backends - Web Backend Meetup May 2014Crate Shared Nothing Web Backends - Web Backend Meetup May 2014
Crate Shared Nothing Web Backends - Web Backend Meetup May 2014
Matthias Wahl
?
Os Balog
Os BalogOs Balog
Os Balog
oscon2007
?
CloudStack and cloud-init
CloudStack and cloud-initCloudStack and cloud-init
CloudStack and cloud-init
MarcusS13
?
LSA2 - 02 Namespaces
LSA2 - 02  NamespacesLSA2 - 02  Namespaces
LSA2 - 02 Namespaces
Marian Marinov
?
Advanced Replication
Advanced ReplicationAdvanced Replication
Advanced Replication
MongoDB
?
Hydra - Getting Started
Hydra - Getting StartedHydra - Getting Started
Hydra - Getting Started
abramsm
?
Re: ?????????????
Re: ?????????????Re: ?????????????
Re: ?????????????
Mario Cho
?
LSA2 - PostgreSQL
LSA2 - PostgreSQLLSA2 - PostgreSQL
LSA2 - PostgreSQL
Marian Marinov
?
Cocoon Blocks ApacheCon US 2005
Cocoon Blocks ApacheCon US 2005Cocoon Blocks ApacheCon US 2005
Cocoon Blocks ApacheCon US 2005
Daniel Fagerstrom
?
The TCP/IP stack in the FreeBSD kernel COSCUP 2014
The TCP/IP stack in the FreeBSD kernel COSCUP 2014The TCP/IP stack in the FreeBSD kernel COSCUP 2014
The TCP/IP stack in the FreeBSD kernel COSCUP 2014
Kevin Lo
?
¶Ù´Ç³¦°ì±ð°ù¤ÎœÊ±¸
¶Ù´Ç³¦°ì±ð°ù¤ÎœÊ±¸¶Ù´Ç³¦°ì±ð°ù¤ÎœÊ±¸
¶Ù´Ç³¦°ì±ð°ù¤ÎœÊ±¸
koedoyoshida
?
Scale11x lxc talk
Scale11x lxc talkScale11x lxc talk
Scale11x lxc talk
dotCloud
?
RapidInsight for OpenNMS
RapidInsight for OpenNMSRapidInsight for OpenNMS
RapidInsight for OpenNMS
mberkay
?
Archlinux install
Archlinux installArchlinux install
Archlinux install
sambismo
?
Introduction to-linux
Introduction to-linuxIntroduction to-linux
Introduction to-linux
rowiebornia
?
Bower introduction
Bower introductionBower introduction
Bower introduction
Oleksii Prohonnyi
?
Replica Sets (NYC NoSQL Meetup)
Replica Sets (NYC NoSQL Meetup)Replica Sets (NYC NoSQL Meetup)
Replica Sets (NYC NoSQL Meetup)
MongoDB
?
Using MMS to Build New Environments
Using MMS to Build New EnvironmentsUsing MMS to Build New Environments
Using MMS to Build New Environments
MongoDB
?
¡¾Unity¡¿Scriptable object ÈëéT¤È»îÓÃÀý
¡¾Unity¡¿Scriptable object ÈëéT¤È»îÓÃÀý¡¾Unity¡¿Scriptable object ÈëéT¤È»îÓÃÀý
¡¾Unity¡¿Scriptable object ÈëéT¤È»îÓÃÀý
Unity Technologies Japan K.K.
?
MySQL Slow Query log Monitoring using Beats & ELK
MySQL Slow Query log Monitoring using Beats & ELKMySQL Slow Query log Monitoring using Beats & ELK
MySQL Slow Query log Monitoring using Beats & ELK
I Goo Lee
?
Crate Shared Nothing Web Backends - Web Backend Meetup May 2014
Crate Shared Nothing Web Backends - Web Backend Meetup May 2014Crate Shared Nothing Web Backends - Web Backend Meetup May 2014
Crate Shared Nothing Web Backends - Web Backend Meetup May 2014
Matthias Wahl
?
CloudStack and cloud-init
CloudStack and cloud-initCloudStack and cloud-init
CloudStack and cloud-init
MarcusS13
?
Advanced Replication
Advanced ReplicationAdvanced Replication
Advanced Replication
MongoDB
?
Hydra - Getting Started
Hydra - Getting StartedHydra - Getting Started
Hydra - Getting Started
abramsm
?
Re: ?????????????
Re: ?????????????Re: ?????????????
Re: ?????????????
Mario Cho
?
Cocoon Blocks ApacheCon US 2005
Cocoon Blocks ApacheCon US 2005Cocoon Blocks ApacheCon US 2005
Cocoon Blocks ApacheCon US 2005
Daniel Fagerstrom
?
The TCP/IP stack in the FreeBSD kernel COSCUP 2014
The TCP/IP stack in the FreeBSD kernel COSCUP 2014The TCP/IP stack in the FreeBSD kernel COSCUP 2014
The TCP/IP stack in the FreeBSD kernel COSCUP 2014
Kevin Lo
?
¶Ù´Ç³¦°ì±ð°ù¤ÎœÊ±¸
¶Ù´Ç³¦°ì±ð°ù¤ÎœÊ±¸¶Ù´Ç³¦°ì±ð°ù¤ÎœÊ±¸
¶Ù´Ç³¦°ì±ð°ù¤ÎœÊ±¸
koedoyoshida
?
Scale11x lxc talk
Scale11x lxc talkScale11x lxc talk
Scale11x lxc talk
dotCloud
?
RapidInsight for OpenNMS
RapidInsight for OpenNMSRapidInsight for OpenNMS
RapidInsight for OpenNMS
mberkay
?
Archlinux install
Archlinux installArchlinux install
Archlinux install
sambismo
?
Introduction to-linux
Introduction to-linuxIntroduction to-linux
Introduction to-linux
rowiebornia
?
Replica Sets (NYC NoSQL Meetup)
Replica Sets (NYC NoSQL Meetup)Replica Sets (NYC NoSQL Meetup)
Replica Sets (NYC NoSQL Meetup)
MongoDB
?
Using MMS to Build New Environments
Using MMS to Build New EnvironmentsUsing MMS to Build New Environments
Using MMS to Build New Environments
MongoDB
?

Similar to Node.js and websockets intro (20)

Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredev
Felix Geisend?rfer
?
How we're building Wercker
How we're building WerckerHow we're building Wercker
How we're building Wercker
Micha Hernandez van Leuffen
?
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)
CODE WHITE GmbH
?
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 Intro
Nodejs IntroNodejs Intro
Nodejs Intro
PavingWays Ltd.
?
SenchaLabs Connect & Express
SenchaLabs Connect & ExpressSenchaLabs Connect & Express
SenchaLabs Connect & Express
Tim Caswell
?
Web Standards @ Opera Talk Oslo
Web Standards @ Opera Talk OsloWeb Standards @ Opera Talk Oslo
Web Standards @ Opera Talk Oslo
Zi Bin Cheah
?
Real Time Web - What's that for?
Real Time Web - What's that for?Real Time Web - What's that for?
Real Time Web - What's that for?
Martyn Loughran
?
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSockets
Gonzalo Ayuso
?
Node.js and Ruby
Node.js and RubyNode.js and Ruby
Node.js and Ruby
Michael Bleigh
?
XQuery Design Patterns
XQuery Design PatternsXQuery Design Patterns
XQuery Design Patterns
William Candillon
?
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
Ricardo Silva
?
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
soft-shake.ch
?
Comet with node.js and V8
Comet with node.js and V8Comet with node.js and V8
Comet with node.js and V8
amix3k
?
Open End To End Js Stack
Open End To End Js StackOpen End To End Js Stack
Open End To End Js Stack
Skills Matter
?
Bootstrap of Node.js Core (OpenJS Collaborator Summit Berlin 2019)
Bootstrap of Node.js Core (OpenJS Collaborator Summit Berlin 2019)Bootstrap of Node.js Core (OpenJS Collaborator Summit Berlin 2019)
Bootstrap of Node.js Core (OpenJS Collaborator Summit Berlin 2019)
Igalia
?
Web Crawling with NodeJS
Web Crawling with NodeJSWeb Crawling with NodeJS
Web Crawling with NodeJS
Sylvain Zimmer
?
Node js introduction
Node js introductionNode js introduction
Node js introduction
Joseph de Castelnau
?
Java Deserialization Vulnerabilities - The Forgotten Bug Class
Java Deserialization Vulnerabilities - The Forgotten Bug ClassJava Deserialization Vulnerabilities - The Forgotten Bug Class
Java Deserialization Vulnerabilities - The Forgotten Bug Class
CODE WHITE GmbH
?
Watir Presentation Sumanth Krishna. A
Watir Presentation   Sumanth Krishna. AWatir Presentation   Sumanth Krishna. A
Watir Presentation Sumanth Krishna. A
Sumanth krishna
?
Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredev
Felix Geisend?rfer
?
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)
CODE WHITE GmbH
?
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
?
SenchaLabs Connect & Express
SenchaLabs Connect & ExpressSenchaLabs Connect & Express
SenchaLabs Connect & Express
Tim Caswell
?
Web Standards @ Opera Talk Oslo
Web Standards @ Opera Talk OsloWeb Standards @ Opera Talk Oslo
Web Standards @ Opera Talk Oslo
Zi Bin Cheah
?
Real Time Web - What's that for?
Real Time Web - What's that for?Real Time Web - What's that for?
Real Time Web - What's that for?
Martyn Loughran
?
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
Ricardo Silva
?
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
soft-shake.ch
?
Comet with node.js and V8
Comet with node.js and V8Comet with node.js and V8
Comet with node.js and V8
amix3k
?
Open End To End Js Stack
Open End To End Js StackOpen End To End Js Stack
Open End To End Js Stack
Skills Matter
?
Bootstrap of Node.js Core (OpenJS Collaborator Summit Berlin 2019)
Bootstrap of Node.js Core (OpenJS Collaborator Summit Berlin 2019)Bootstrap of Node.js Core (OpenJS Collaborator Summit Berlin 2019)
Bootstrap of Node.js Core (OpenJS Collaborator Summit Berlin 2019)
Igalia
?
Java Deserialization Vulnerabilities - The Forgotten Bug Class
Java Deserialization Vulnerabilities - The Forgotten Bug ClassJava Deserialization Vulnerabilities - The Forgotten Bug Class
Java Deserialization Vulnerabilities - The Forgotten Bug Class
CODE WHITE GmbH
?
Watir Presentation Sumanth Krishna. A
Watir Presentation   Sumanth Krishna. AWatir Presentation   Sumanth Krishna. A
Watir Presentation Sumanth Krishna. A
Sumanth krishna
?

Recently uploaded (20)

AI in Talent Acquisition: Boosting Hiring
AI in Talent Acquisition: Boosting HiringAI in Talent Acquisition: Boosting Hiring
AI in Talent Acquisition: Boosting Hiring
Beyond Chiefs
?
Building High-Impact Teams Beyond the Product Triad.pdf
Building High-Impact Teams Beyond the Product Triad.pdfBuilding High-Impact Teams Beyond the Product Triad.pdf
Building High-Impact Teams Beyond the Product Triad.pdf
Rafael Burity
?
Least Privilege AWS IAM Role Permissions
Least Privilege AWS IAM Role PermissionsLeast Privilege AWS IAM Role Permissions
Least Privilege AWS IAM Role Permissions
Chris Wahl
?
GDG Cloud Southlake #41: Shay Levi: Beyond the Hype:How Enterprises Are Using AI
GDG Cloud Southlake #41: Shay Levi: Beyond the Hype:How Enterprises Are Using AIGDG Cloud Southlake #41: Shay Levi: Beyond the Hype:How Enterprises Are Using AI
GDG Cloud Southlake #41: Shay Levi: Beyond the Hype:How Enterprises Are Using AI
James Anderson
?
Testing Tools for Accessibility Enhancement Part II.pptx
Testing Tools for Accessibility Enhancement Part II.pptxTesting Tools for Accessibility Enhancement Part II.pptx
Testing Tools for Accessibility Enhancement Part II.pptx
Julia Undeutsch
?
Beyond the life of a CISO - Head of Trust at GDG Kathmandu Monthly Meetup
Beyond the life of a CISO -  Head of Trust at GDG Kathmandu Monthly MeetupBeyond the life of a CISO -  Head of Trust at GDG Kathmandu Monthly Meetup
Beyond the life of a CISO - Head of Trust at GDG Kathmandu Monthly Meetup
GDG Kathmandu
?
The Road to SAP S4HANA Cloud with SAP Activate.pptx
The Road to SAP S4HANA Cloud with SAP Activate.pptxThe Road to SAP S4HANA Cloud with SAP Activate.pptx
The Road to SAP S4HANA Cloud with SAP Activate.pptx
zsbaranyai
?
Recruiting Tech: A Look at Why AI is Actually OG
Recruiting Tech: A Look at Why AI is Actually OGRecruiting Tech: A Look at Why AI is Actually OG
Recruiting Tech: A Look at Why AI is Actually OG
Matt Charney
?
Scalable Multi-Agent AI with AutoGen by Udai
Scalable Multi-Agent AI with AutoGen by UdaiScalable Multi-Agent AI with AutoGen by Udai
Scalable Multi-Agent AI with AutoGen by Udai
Udaiappa Ramachandran
?
Getting the Best of TrueDEM ¨C April News & Updates
Getting the Best of TrueDEM ¨C April News & UpdatesGetting the Best of TrueDEM ¨C April News & Updates
Getting the Best of TrueDEM ¨C April News & Updates
panagenda
?
AuthZEN The OpenID Connect of Authorization - Gartner IAM EMEA 2025
AuthZEN The OpenID Connect of Authorization - Gartner IAM EMEA 2025AuthZEN The OpenID Connect of Authorization - Gartner IAM EMEA 2025
AuthZEN The OpenID Connect of Authorization - Gartner IAM EMEA 2025
David Brossard
?
Leadership Spectrum by Sonam Sherpa at GDG Kathmandu March Monthly Meetup
Leadership Spectrum by Sonam Sherpa at GDG Kathmandu March Monthly MeetupLeadership Spectrum by Sonam Sherpa at GDG Kathmandu March Monthly Meetup
Leadership Spectrum by Sonam Sherpa at GDG Kathmandu March Monthly Meetup
GDG Kathmandu
?
ScotSecure Cyber Security Summit 2025 Edinburgh
ScotSecure Cyber Security Summit 2025 EdinburghScotSecure Cyber Security Summit 2025 Edinburgh
ScotSecure Cyber Security Summit 2025 Edinburgh
Ray Bugg
?
202408_JAWSPANKRATION_Introduction_of_Minaden.pdf
202408_JAWSPANKRATION_Introduction_of_Minaden.pdf202408_JAWSPANKRATION_Introduction_of_Minaden.pdf
202408_JAWSPANKRATION_Introduction_of_Minaden.pdf
NTTDOCOMO-ServiceInnovation
?
STARLINK-JIO-AIRTEL Security issues to Ponder
STARLINK-JIO-AIRTEL Security issues to PonderSTARLINK-JIO-AIRTEL Security issues to Ponder
STARLINK-JIO-AIRTEL Security issues to Ponder
anupriti
?
Research Data Management (RDM): the management of dat in the research process
Research Data Management (RDM): the management of dat in the research processResearch Data Management (RDM): the management of dat in the research process
Research Data Management (RDM): the management of dat in the research process
HeilaPienaar
?
A General introduction to Ad ranking algorithms
A General introduction to Ad ranking algorithmsA General introduction to Ad ranking algorithms
A General introduction to Ad ranking algorithms
Buhwan Jeong
?
UiPath NY AI Series: Session 4: UiPath AutoPilot for Developers using Studio Web
UiPath NY AI Series: Session 4: UiPath AutoPilot for Developers using Studio WebUiPath NY AI Series: Session 4: UiPath AutoPilot for Developers using Studio Web
UiPath NY AI Series: Session 4: UiPath AutoPilot for Developers using Studio Web
DianaGray10
?
Solana Developer Hiring for Enterprises Key Considerations.pdf
Solana Developer Hiring for Enterprises Key Considerations.pdfSolana Developer Hiring for Enterprises Key Considerations.pdf
Solana Developer Hiring for Enterprises Key Considerations.pdf
Lisa ward
?
Next.js Development: The Ultimate Solution for High-Performance Web Apps
Next.js Development: The Ultimate Solution for High-Performance Web AppsNext.js Development: The Ultimate Solution for High-Performance Web Apps
Next.js Development: The Ultimate Solution for High-Performance Web Apps
rwinfotech31
?
AI in Talent Acquisition: Boosting Hiring
AI in Talent Acquisition: Boosting HiringAI in Talent Acquisition: Boosting Hiring
AI in Talent Acquisition: Boosting Hiring
Beyond Chiefs
?
Building High-Impact Teams Beyond the Product Triad.pdf
Building High-Impact Teams Beyond the Product Triad.pdfBuilding High-Impact Teams Beyond the Product Triad.pdf
Building High-Impact Teams Beyond the Product Triad.pdf
Rafael Burity
?
Least Privilege AWS IAM Role Permissions
Least Privilege AWS IAM Role PermissionsLeast Privilege AWS IAM Role Permissions
Least Privilege AWS IAM Role Permissions
Chris Wahl
?
GDG Cloud Southlake #41: Shay Levi: Beyond the Hype:How Enterprises Are Using AI
GDG Cloud Southlake #41: Shay Levi: Beyond the Hype:How Enterprises Are Using AIGDG Cloud Southlake #41: Shay Levi: Beyond the Hype:How Enterprises Are Using AI
GDG Cloud Southlake #41: Shay Levi: Beyond the Hype:How Enterprises Are Using AI
James Anderson
?
Testing Tools for Accessibility Enhancement Part II.pptx
Testing Tools for Accessibility Enhancement Part II.pptxTesting Tools for Accessibility Enhancement Part II.pptx
Testing Tools for Accessibility Enhancement Part II.pptx
Julia Undeutsch
?
Beyond the life of a CISO - Head of Trust at GDG Kathmandu Monthly Meetup
Beyond the life of a CISO -  Head of Trust at GDG Kathmandu Monthly MeetupBeyond the life of a CISO -  Head of Trust at GDG Kathmandu Monthly Meetup
Beyond the life of a CISO - Head of Trust at GDG Kathmandu Monthly Meetup
GDG Kathmandu
?
The Road to SAP S4HANA Cloud with SAP Activate.pptx
The Road to SAP S4HANA Cloud with SAP Activate.pptxThe Road to SAP S4HANA Cloud with SAP Activate.pptx
The Road to SAP S4HANA Cloud with SAP Activate.pptx
zsbaranyai
?
Recruiting Tech: A Look at Why AI is Actually OG
Recruiting Tech: A Look at Why AI is Actually OGRecruiting Tech: A Look at Why AI is Actually OG
Recruiting Tech: A Look at Why AI is Actually OG
Matt Charney
?
Scalable Multi-Agent AI with AutoGen by Udai
Scalable Multi-Agent AI with AutoGen by UdaiScalable Multi-Agent AI with AutoGen by Udai
Scalable Multi-Agent AI with AutoGen by Udai
Udaiappa Ramachandran
?
Getting the Best of TrueDEM ¨C April News & Updates
Getting the Best of TrueDEM ¨C April News & UpdatesGetting the Best of TrueDEM ¨C April News & Updates
Getting the Best of TrueDEM ¨C April News & Updates
panagenda
?
AuthZEN The OpenID Connect of Authorization - Gartner IAM EMEA 2025
AuthZEN The OpenID Connect of Authorization - Gartner IAM EMEA 2025AuthZEN The OpenID Connect of Authorization - Gartner IAM EMEA 2025
AuthZEN The OpenID Connect of Authorization - Gartner IAM EMEA 2025
David Brossard
?
Leadership Spectrum by Sonam Sherpa at GDG Kathmandu March Monthly Meetup
Leadership Spectrum by Sonam Sherpa at GDG Kathmandu March Monthly MeetupLeadership Spectrum by Sonam Sherpa at GDG Kathmandu March Monthly Meetup
Leadership Spectrum by Sonam Sherpa at GDG Kathmandu March Monthly Meetup
GDG Kathmandu
?
ScotSecure Cyber Security Summit 2025 Edinburgh
ScotSecure Cyber Security Summit 2025 EdinburghScotSecure Cyber Security Summit 2025 Edinburgh
ScotSecure Cyber Security Summit 2025 Edinburgh
Ray Bugg
?
STARLINK-JIO-AIRTEL Security issues to Ponder
STARLINK-JIO-AIRTEL Security issues to PonderSTARLINK-JIO-AIRTEL Security issues to Ponder
STARLINK-JIO-AIRTEL Security issues to Ponder
anupriti
?
Research Data Management (RDM): the management of dat in the research process
Research Data Management (RDM): the management of dat in the research processResearch Data Management (RDM): the management of dat in the research process
Research Data Management (RDM): the management of dat in the research process
HeilaPienaar
?
A General introduction to Ad ranking algorithms
A General introduction to Ad ranking algorithmsA General introduction to Ad ranking algorithms
A General introduction to Ad ranking algorithms
Buhwan Jeong
?
UiPath NY AI Series: Session 4: UiPath AutoPilot for Developers using Studio Web
UiPath NY AI Series: Session 4: UiPath AutoPilot for Developers using Studio WebUiPath NY AI Series: Session 4: UiPath AutoPilot for Developers using Studio Web
UiPath NY AI Series: Session 4: UiPath AutoPilot for Developers using Studio Web
DianaGray10
?
Solana Developer Hiring for Enterprises Key Considerations.pdf
Solana Developer Hiring for Enterprises Key Considerations.pdfSolana Developer Hiring for Enterprises Key Considerations.pdf
Solana Developer Hiring for Enterprises Key Considerations.pdf
Lisa ward
?
Next.js Development: The Ultimate Solution for High-Performance Web Apps
Next.js Development: The Ultimate Solution for High-Performance Web AppsNext.js Development: The Ultimate Solution for High-Performance Web Apps
Next.js Development: The Ultimate Solution for High-Performance Web Apps
rwinfotech31
?

Node.js and websockets intro

  • 1. Node.js and WebSockets A (very) short introduction Andreas Kompanez Montag, 26. April 2010
  • 2. Node.js JavaScript Framework Server-side Uses V8 Evented and non-blocking CommonJS Uses ECMAScript 5 Montag, 26. April 2010
  • 3. Node.js Created by Ryan Dahl ~8000 lines of C/C++ and 2000 lines JavaScript http://nodejs.org/ Montag, 26. April 2010
  • 4. Evented? Old (blocking) school: <?php $content = file_get_contents("/some/huge/file"); doThings($content); // Waiting, synchron otherThing(); Montag, 26. April 2010
  • 5. Evented? Evented I/O file.read("/some/huge/file", function(data) { // called after data is read doThings(data); }); otherThing(); // execute immediately; Montag, 26. April 2010
  • 6. Benefits Asynchronous programming Event-loops instead of threads Non-blocking 1 Thread (No context switching etc.) Montag, 26. April 2010
  • 8. CommonJS A collection/library of standards Modules Binary File system and many more! Montag, 26. April 2010
  • 9. CommonJS Modules There should be a function require There should be a var called exports Montag, 26. April 2010
  • 10. Module Example // math.js module exports.multiply = function(a, b) { return a * b; } // Some other file, using math.js // var math = require('./math'); var sys = require('sys'); sys.puts(math.multiply(12, 12)); Montag, 26. April 2010
  • 11. Google V8 JavaScript Engine It¡¯s a VM! Developed by Google The team lead is Lars Bak (Sun¡¯s Java VM & Smalltalk VM) No JIT, compiled to Assembler Montag, 26. April 2010
  • 12. The 6+ lines http server // httpserver.js // Usage: node httpserver.js var sys = require("sys"), http = require("http"); http.createServer(function(request, response) { var headers = { "Content-Type": "text/plain" }; response.sendHeader(200, headers); response.write("Hello, World!n"); response.close(); }).listen(8000); sys.puts("Running at http://127.0.0.1:8000/"); Montag, 26. April 2010
  • 14. WebSockets A HTML5 standard Allows bidirectional communications Less overhead than HTTP/AJAX (less headers) Cross domain Montag, 26. April 2010
  • 15. Polling Client Mailman Server Montag, 26. April 2010
  • 16. Bidirectional Client Telephone Server Montag, 26. April 2010
  • 17. WS Communication details Handshake GET /test HTTP/1.1 HTTP/1.1 101 Web Socket Protocol Handshake Upgrade: WebSocket Upgrade: WebSocket Connection: Upgrade Connection: Upgrade Origin: http://localhost/test Server: Resin/4.0.2 Host: localhost WebSocket-Location: ws://localhost/websocket Content-Length: 0 WebSocket-Origin: http://localhost/test Content-Length: 0 Date: Fri, 08 May 2009 09:51:31 GMT Messages x00hello, worldxff Montag, 26. April 2010
  • 18. WebSockets Client- side if (("WebSocket" in window)) { var ws = new WebSocket("ws://localhost:8080/"); ws.onmessage = function(evt) { // Receive }; ws.onopen = function(evt) { // ws.send('Oh hai'); }; ws.onclose = function(evt) { // }; ws.onerror = function(evt) { // }; ws.close(); } Montag, 26. April 2010