SlideShare une entreprise Scribd logo
1  sur  19
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

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 & ELKI 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 2014Matthias Wahl
 
CloudStack and cloud-init
CloudStack and cloud-initCloudStack and cloud-init
CloudStack and cloud-initMarcusS13
 
Advanced Replication
Advanced ReplicationAdvanced Replication
Advanced ReplicationMongoDB
 
Hydra - Getting Started
Hydra - Getting StartedHydra - Getting Started
Hydra - Getting Startedabramsm
 
Re: 제로부터시작하는텐서플로우
Re: 제로부터시작하는텐서플로우Re: 제로부터시작하는텐서플로우
Re: 제로부터시작하는텐서플로우Mario Cho
 
Cocoon Blocks ApacheCon US 2005
Cocoon Blocks ApacheCon US 2005Cocoon Blocks ApacheCon US 2005
Cocoon Blocks ApacheCon US 2005Daniel 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 2014Kevin Lo
 
Scale11x lxc talk
Scale11x lxc talkScale11x lxc talk
Scale11x lxc talkdotCloud
 
RapidInsight for OpenNMS
RapidInsight for OpenNMSRapidInsight for OpenNMS
RapidInsight for OpenNMSmberkay
 
Archlinux install
Archlinux installArchlinux install
Archlinux installsambismo
 
Introduction to-linux
Introduction to-linuxIntroduction to-linux
Introduction to-linuxrowiebornia
 
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 EnvironmentsMongoDB
 

Tendances (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
 
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
 
Os Balog
Os BalogOs Balog
Os Balog
 
CloudStack and cloud-init
CloudStack and cloud-initCloudStack and cloud-init
CloudStack and cloud-init
 
LSA2 - 02 Namespaces
LSA2 - 02  NamespacesLSA2 - 02  Namespaces
LSA2 - 02 Namespaces
 
Advanced Replication
Advanced ReplicationAdvanced Replication
Advanced Replication
 
Hydra - Getting Started
Hydra - Getting StartedHydra - Getting Started
Hydra - Getting Started
 
Re: 제로부터시작하는텐서플로우
Re: 제로부터시작하는텐서플로우Re: 제로부터시작하는텐서플로우
Re: 제로부터시작하는텐서플로우
 
LSA2 - PostgreSQL
LSA2 - PostgreSQLLSA2 - PostgreSQL
LSA2 - PostgreSQL
 
Cocoon Blocks ApacheCon US 2005
Cocoon Blocks ApacheCon US 2005Cocoon Blocks ApacheCon US 2005
Cocoon Blocks ApacheCon US 2005
 
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
 
Dockerの準備
Dockerの準備Dockerの準備
Dockerの準備
 
Scale11x lxc talk
Scale11x lxc talkScale11x lxc talk
Scale11x lxc talk
 
RapidInsight for OpenNMS
RapidInsight for OpenNMSRapidInsight for OpenNMS
RapidInsight for OpenNMS
 
Archlinux install
Archlinux installArchlinux install
Archlinux install
 
Introduction to-linux
Introduction to-linuxIntroduction to-linux
Introduction to-linux
 
Bower introduction
Bower introductionBower introduction
Bower introduction
 
Replica Sets (NYC NoSQL Meetup)
Replica Sets (NYC NoSQL Meetup)Replica Sets (NYC NoSQL Meetup)
Replica Sets (NYC NoSQL Meetup)
 
Using MMS to Build New Environments
Using MMS to Build New EnvironmentsUsing MMS to Build New Environments
Using MMS to Build New Environments
 
【Unity】Scriptable object 入門と活用例
【Unity】Scriptable object 入門と活用例【Unity】Scriptable object 入門と活用例
【Unity】Scriptable object 入門と活用例
 

Similaire à Node.js and websockets intro

Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevFelix 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 & ExpressTim Caswell
 
Web Standards @ Opera Talk Oslo
Web Standards @ Opera Talk OsloWeb Standards @ Opera Talk Oslo
Web Standards @ Opera Talk OsloZi 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 WebSocketsGonzalo Ayuso
 
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
 
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
 
Comet with node.js and V8
Comet with node.js and V8Comet with node.js and V8
Comet with node.js and V8amix3k
 
Open End To End Js Stack
Open End To End Js StackOpen End To End Js Stack
Open End To End Js StackSkills 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 NodeJSSylvain Zimmer
 
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 ClassCODE WHITE GmbH
 
Watir Presentation Sumanth Krishna. A
Watir Presentation   Sumanth Krishna. AWatir Presentation   Sumanth Krishna. A
Watir Presentation Sumanth Krishna. ASumanth krishna
 

Similaire à 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
 
How we're building Wercker
How we're building WerckerHow we're building Wercker
How we're building Wercker
 
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)
 
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 Intro
Nodejs IntroNodejs Intro
Nodejs Intro
 
SenchaLabs Connect & Express
SenchaLabs Connect & ExpressSenchaLabs Connect & Express
SenchaLabs Connect & Express
 
Web Standards @ Opera Talk Oslo
Web Standards @ Opera Talk OsloWeb Standards @ Opera Talk Oslo
Web Standards @ Opera Talk Oslo
 
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?
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSockets
 
Node.js and Ruby
Node.js and RubyNode.js and Ruby
Node.js and Ruby
 
XQuery Design Patterns
XQuery Design PatternsXQuery Design Patterns
XQuery Design Patterns
 
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
 
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
 
Comet with node.js and V8
Comet with node.js and V8Comet with node.js and V8
Comet with node.js and V8
 
Open End To End Js Stack
Open End To End Js StackOpen End To End Js Stack
Open End To End Js Stack
 
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)
 
Web Crawling with NodeJS
Web Crawling with NodeJSWeb Crawling with NodeJS
Web Crawling with NodeJS
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 
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
 
Watir Presentation Sumanth Krishna. A
Watir Presentation   Sumanth Krishna. AWatir Presentation   Sumanth Krishna. A
Watir Presentation Sumanth Krishna. A
 

Dernier

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 

Dernier (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 

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