SlideShare a Scribd company logo
1 of 16
Jugando con
websockets en

   Israel Gutiérrez
NodeJS
• Server side JavaScript
• Platform built over Chrome’s v8
• Event driven (asynchronous)
• Applications
 • Data-intensive (efficiency)
 • Real-time (websockets)
NodeJS architecture
npm

• node package manager
 • express (routing)
 • socket.io (websockets)
 • mongo (database drivers)
 • ...
Application stack
• HTTP server (or TCP-socket or
  websockets)
• Router
• Request handlers
 • Handle data received
 • View logic
HTTP server

var http = require("http");

http.createServer(function(request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.write("Hello World");
  response.end();
}).listen(8888);
TCP server
var net = require('net');

var server = net.createServer(function (socket) {
  socket.write('Echo serverrn');
  socket.pipe(socket);
});

server.listen(1337, '127.0.0.1');
Modules
server.js
var http = require("http");

function start() {
  function onRequest(request, response) {
    console.log("Request received.");
    response.writeHead(200, {"Content-Type": "text/plain"});
    response.write("Hello World");
    response.end();
  }

  http.createServer(onRequest).listen(8888);
  console.log("Server has started.");
}

exports.start = start;


index.js
var server = require("./server");

server.start();
Router and handlers
• You can program the routes based on
  request.url
      var server = require("./server");
      var router = require("./router");
      var requestHandlers = require("./requestHandlers");

      var handle = {}
      handle["/"] = requestHandlers.start;
      handle["/start"] = requestHandlers.start;
      handle["/upload"] = requestHandlers.upload;

      server.start(router.route, handle);




• I recommend using express (Sinatra like)
Templating

• ejs
• underscore
• jade
• ...
Websockets
• Canal de comunicación full duplex
  (bidireccional y a la vez) sobre TCP
• No hay cabeceras HTTP! (menos
  overhead)
• Aplicaciones que requieren interacciones
  en tiempo real
• URL tipo ws://
socket.io
• Websockets library
• Fallbacks
 • Flash
 • AJAX long polling
 • AJAX multipart streaming
 • Forever iframe
 • JSONP polling
socket.io support
    Desktop
•   Internet Explorer 5.5+
•   Safari 3+
•   Google Chrome 4+
•   Firefox 3+
•   Opera 10.61+


Mobile
• iPhone Safari
• iPad Safari
• Android WebKit
• WebOs WebKit
socket.io example
Server
var io = require('socket.io').listen(80);

io.sockets.on('connection', function (socket) {
  socket.emit('news', { hello: 'world' });
  socket.on('my other event', function (data) {
    console.log(data);
  });
});



Client
<script src="/socket.io/socket.io.js"></script>
<script>
  var socket = io.connect('http://localhost');
  socket.on('news', function (data) {
    console.log(data);
    socket.emit('my other event', { my: 'data' });
  });
</script>
References

• http://nodejs.org/
• http://www.nodebeginner.org/
• https://npmjs.org/
• http://socket.io/
• http://www.nodecloud.org/
Let’s do some fucking
        code!!!

More Related Content

What's hot

Rapid dev env DevOps Warsaw July 2014
Rapid dev env DevOps Warsaw July 2014Rapid dev env DevOps Warsaw July 2014
Rapid dev env DevOps Warsaw July 2014blndrt
 
OSMC 2019 | Monitoring Nomad with Prometheus and Icinga by Bram Vogelaar
OSMC 2019 | Monitoring Nomad with Prometheus and Icinga by Bram VogelaarOSMC 2019 | Monitoring Nomad with Prometheus and Icinga by Bram Vogelaar
OSMC 2019 | Monitoring Nomad with Prometheus and Icinga by Bram VogelaarNETWAYS
 
Create Rest API in Nodejs
Create Rest API in Nodejs Create Rest API in Nodejs
Create Rest API in Nodejs Irfan Maulana
 
(WS14) Sasa Matijasic - Node.js i "novi" web
(WS14) Sasa Matijasic - Node.js i "novi" web(WS14) Sasa Matijasic - Node.js i "novi" web
(WS14) Sasa Matijasic - Node.js i "novi" webWeb::Strategija
 
Socket programming, and openresty
Socket programming, and openrestySocket programming, and openresty
Socket programming, and openrestyTavish Naruka
 
Frontend Track NodeJS
Frontend Track NodeJSFrontend Track NodeJS
Frontend Track NodeJSMarcelo Serpa
 
Server side scripting smack down - Node.js vs PHP
Server side scripting smack down - Node.js vs PHPServer side scripting smack down - Node.js vs PHP
Server side scripting smack down - Node.js vs PHPMarc Gear
 
vert.x 3.1 - be reactive on the JVM but not only in Java
vert.x 3.1 - be reactive on the JVM but not only in Javavert.x 3.1 - be reactive on the JVM but not only in Java
vert.x 3.1 - be reactive on the JVM but not only in JavaClément Escoffier
 
SockJS Intro
SockJS IntroSockJS Intro
SockJS IntroNgoc Dao
 
Helma / RingoJS – Vienna.js Minitalk
Helma / RingoJS – Vienna.js MinitalkHelma / RingoJS – Vienna.js Minitalk
Helma / RingoJS – Vienna.js MinitalkPhilipp Naderer
 
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
 
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
 
Introduction to REST API with Node.js
Introduction to REST API with Node.jsIntroduction to REST API with Node.js
Introduction to REST API with Node.jsYoann Gotthilf
 
Complete MVC on NodeJS
Complete MVC on NodeJSComplete MVC on NodeJS
Complete MVC on NodeJSHüseyin BABAL
 

What's hot (19)

Ether mining 101 v2
Ether mining 101 v2Ether mining 101 v2
Ether mining 101 v2
 
Rapid dev env DevOps Warsaw July 2014
Rapid dev env DevOps Warsaw July 2014Rapid dev env DevOps Warsaw July 2014
Rapid dev env DevOps Warsaw July 2014
 
Node.js
Node.jsNode.js
Node.js
 
OSMC 2019 | Monitoring Nomad with Prometheus and Icinga by Bram Vogelaar
OSMC 2019 | Monitoring Nomad with Prometheus and Icinga by Bram VogelaarOSMC 2019 | Monitoring Nomad with Prometheus and Icinga by Bram Vogelaar
OSMC 2019 | Monitoring Nomad with Prometheus and Icinga by Bram Vogelaar
 
Create Rest API in Nodejs
Create Rest API in Nodejs Create Rest API in Nodejs
Create Rest API in Nodejs
 
(WS14) Sasa Matijasic - Node.js i "novi" web
(WS14) Sasa Matijasic - Node.js i "novi" web(WS14) Sasa Matijasic - Node.js i "novi" web
(WS14) Sasa Matijasic - Node.js i "novi" web
 
Socket programming, and openresty
Socket programming, and openrestySocket programming, and openresty
Socket programming, and openresty
 
Frontend Track NodeJS
Frontend Track NodeJSFrontend Track NodeJS
Frontend Track NodeJS
 
Server side scripting smack down - Node.js vs PHP
Server side scripting smack down - Node.js vs PHPServer side scripting smack down - Node.js vs PHP
Server side scripting smack down - Node.js vs PHP
 
vert.x 3.1 - be reactive on the JVM but not only in Java
vert.x 3.1 - be reactive on the JVM but not only in Javavert.x 3.1 - be reactive on the JVM but not only in Java
vert.x 3.1 - be reactive on the JVM but not only in Java
 
SockJS Intro
SockJS IntroSockJS Intro
SockJS Intro
 
WebSocket
WebSocketWebSocket
WebSocket
 
node.js dao
node.js daonode.js dao
node.js dao
 
Helma / RingoJS – Vienna.js Minitalk
Helma / RingoJS – Vienna.js MinitalkHelma / RingoJS – Vienna.js Minitalk
Helma / RingoJS – Vienna.js Minitalk
 
Socket.IO
Socket.IOSocket.IO
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
 
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
 
Introduction to REST API with Node.js
Introduction to REST API with Node.jsIntroduction to REST API with Node.js
Introduction to REST API with Node.js
 
Complete MVC on NodeJS
Complete MVC on NodeJSComplete MVC on NodeJS
Complete MVC on NodeJS
 

Similar to Jugando con websockets en nodeJS

Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSocketsGonzalo Ayuso
 
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
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsRichard Lee
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.jsorkaplan
 
Node.js: The What, The How and The When
Node.js: The What, The How and The WhenNode.js: The What, The How and The When
Node.js: The What, The How and The WhenFITC
 
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
 
Introduction to Node.js: What, why and how?
Introduction to Node.js: What, why and how?Introduction to Node.js: What, why and how?
Introduction to Node.js: What, why and how?Christian Joudrey
 
[FT-8][banacorn] Socket.IO for Haskell Folks
[FT-8][banacorn] Socket.IO for Haskell Folks[FT-8][banacorn] Socket.IO for Haskell Folks
[FT-8][banacorn] Socket.IO for Haskell FolksFunctional Thursday
 
Node.JS and WebSockets with Faye
Node.JS and WebSockets with FayeNode.JS and WebSockets with Faye
Node.JS and WebSockets with FayeMatjaž Lipuš
 
Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevFelix Geisendörfer
 
Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2Asher Martin
 
Asynchronous Web Programming with HTML5 WebSockets and Java
Asynchronous Web Programming with HTML5 WebSockets and JavaAsynchronous Web Programming with HTML5 WebSockets and Java
Asynchronous Web Programming with HTML5 WebSockets and JavaJames Falkner
 
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
 
FITC - Node.js 101
FITC - Node.js 101FITC - Node.js 101
FITC - Node.js 101Rami Sayar
 
Node.js - The New, New Hotness
Node.js - The New, New HotnessNode.js - The New, New Hotness
Node.js - The New, New HotnessDaniel Shaw
 
Introduction to Ethereum
Introduction to EthereumIntroduction to Ethereum
Introduction to EthereumArnold Pham
 

Similar to Jugando con websockets en nodeJS (20)

Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSockets
 
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
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Node.js: The What, The How and The When
Node.js: The What, The How and The WhenNode.js: The What, The How and The When
Node.js: The What, The How and The When
 
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
 
Introduction to Node.js: What, why and how?
Introduction to Node.js: What, why and how?Introduction to Node.js: What, why and how?
Introduction to Node.js: What, why and how?
 
[FT-8][banacorn] Socket.IO for Haskell Folks
[FT-8][banacorn] Socket.IO for Haskell Folks[FT-8][banacorn] Socket.IO for Haskell Folks
[FT-8][banacorn] Socket.IO for Haskell Folks
 
Node.JS and WebSockets with Faye
Node.JS and WebSockets with FayeNode.JS and WebSockets with Faye
Node.JS and WebSockets with Faye
 
Building Client-Side Attacks with HTML5 Features
Building Client-Side Attacks with HTML5 FeaturesBuilding Client-Side Attacks with HTML5 Features
Building Client-Side Attacks with HTML5 Features
 
Socket.io
Socket.ioSocket.io
Socket.io
 
What is Node.js
What is Node.jsWhat is Node.js
What is Node.js
 
Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredev
 
Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2
 
Asynchronous Web Programming with HTML5 WebSockets and Java
Asynchronous Web Programming with HTML5 WebSockets and JavaAsynchronous Web Programming with HTML5 WebSockets and Java
Asynchronous Web Programming with HTML5 WebSockets and Java
 
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
 
FITC - Node.js 101
FITC - Node.js 101FITC - Node.js 101
FITC - Node.js 101
 
Node.js - The New, New Hotness
Node.js - The New, New HotnessNode.js - The New, New Hotness
Node.js - The New, New Hotness
 
signalr
signalrsignalr
signalr
 
Introduction to Ethereum
Introduction to EthereumIntroduction to Ethereum
Introduction to Ethereum
 

More from Israel Gutiérrez

Make startup development great again!
Make startup development great again!Make startup development great again!
Make startup development great again!Israel Gutiérrez
 
Emoticritico: midiendo las emociones de los políticos
Emoticritico: midiendo las emociones de los políticosEmoticritico: midiendo las emociones de los políticos
Emoticritico: midiendo las emociones de los políticosIsrael Gutiérrez
 
Boost your ProDADtivity: productivity tips for entrepreneurial dads and mums
Boost your ProDADtivity: productivity tips for entrepreneurial dads and mums Boost your ProDADtivity: productivity tips for entrepreneurial dads and mums
Boost your ProDADtivity: productivity tips for entrepreneurial dads and mums Israel Gutiérrez
 
Learning Analytics Support for Just-in-time Teaching
Learning Analytics Support for Just-in-time TeachingLearning Analytics Support for Just-in-time Teaching
Learning Analytics Support for Just-in-time TeachingIsrael Gutiérrez
 
Transfórmate en un profesor con superpoderes
Transfórmate en un profesor con superpoderesTransfórmate en un profesor con superpoderes
Transfórmate en un profesor con superpoderesIsrael Gutiérrez
 
Enhancing orchestration of lab sessions by means of awareness mechanisms
Enhancing orchestration of lab sessions by means of awareness mechanismsEnhancing orchestration of lab sessions by means of awareness mechanisms
Enhancing orchestration of lab sessions by means of awareness mechanismsIsrael Gutiérrez
 
Pushing the awareness envelope
Pushing the awareness envelopePushing the awareness envelope
Pushing the awareness envelopeIsrael Gutiérrez
 
Orchestration and Feedback in Lab Sessions: ECTEL11
Orchestration and Feedback in Lab Sessions: ECTEL11Orchestration and Feedback in Lab Sessions: ECTEL11
Orchestration and Feedback in Lab Sessions: ECTEL11Israel Gutiérrez
 
JTELSS11 gradient presentation
JTELSS11 gradient presentationJTELSS11 gradient presentation
JTELSS11 gradient presentationIsrael Gutiérrez
 
Research questions by the Blueberries
Research questions by the BlueberriesResearch questions by the Blueberries
Research questions by the BlueberriesIsrael Gutiérrez
 
Management of Assessment Resources in a Federated Repository of Educational R...
Management of Assessment Resources in a Federated Repository of Educational R...Management of Assessment Resources in a Federated Repository of Educational R...
Management of Assessment Resources in a Federated Repository of Educational R...Israel Gutiérrez
 

More from Israel Gutiérrez (17)

All you need is front
All you need is frontAll you need is front
All you need is front
 
Make startup development great again!
Make startup development great again!Make startup development great again!
Make startup development great again!
 
Emoticritico: midiendo las emociones de los políticos
Emoticritico: midiendo las emociones de los políticosEmoticritico: midiendo las emociones de los políticos
Emoticritico: midiendo las emociones de los políticos
 
Boost your ProDADtivity: productivity tips for entrepreneurial dads and mums
Boost your ProDADtivity: productivity tips for entrepreneurial dads and mums Boost your ProDADtivity: productivity tips for entrepreneurial dads and mums
Boost your ProDADtivity: productivity tips for entrepreneurial dads and mums
 
Learning Analytics Support for Just-in-time Teaching
Learning Analytics Support for Just-in-time TeachingLearning Analytics Support for Just-in-time Teaching
Learning Analytics Support for Just-in-time Teaching
 
Full metal mongo
Full metal mongoFull metal mongo
Full metal mongo
 
Transfórmate en un profesor con superpoderes
Transfórmate en un profesor con superpoderesTransfórmate en un profesor con superpoderes
Transfórmate en un profesor con superpoderes
 
Enhancing orchestration of lab sessions by means of awareness mechanisms
Enhancing orchestration of lab sessions by means of awareness mechanismsEnhancing orchestration of lab sessions by means of awareness mechanisms
Enhancing orchestration of lab sessions by means of awareness mechanisms
 
Pushing the awareness envelope
Pushing the awareness envelopePushing the awareness envelope
Pushing the awareness envelope
 
Stay at KU Leuven
Stay at KU LeuvenStay at KU Leuven
Stay at KU Leuven
 
MongoDB at GUL
MongoDB at GULMongoDB at GUL
MongoDB at GUL
 
Orchestration and Feedback in Lab Sessions: ECTEL11
Orchestration and Feedback in Lab Sessions: ECTEL11Orchestration and Feedback in Lab Sessions: ECTEL11
Orchestration and Feedback in Lab Sessions: ECTEL11
 
The feedback loop revisited
The feedback loop revisitedThe feedback loop revisited
The feedback loop revisited
 
JTELSS11 gradient presentation
JTELSS11 gradient presentationJTELSS11 gradient presentation
JTELSS11 gradient presentation
 
Research questions by the Blueberries
Research questions by the BlueberriesResearch questions by the Blueberries
Research questions by the Blueberries
 
Seminario eMadrid
Seminario eMadridSeminario eMadrid
Seminario eMadrid
 
Management of Assessment Resources in a Federated Repository of Educational R...
Management of Assessment Resources in a Federated Repository of Educational R...Management of Assessment Resources in a Federated Repository of Educational R...
Management of Assessment Resources in a Federated Repository of Educational R...
 

Recently uploaded

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 

Recently uploaded (20)

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 

Jugando con websockets en nodeJS

  • 1. Jugando con websockets en Israel Gutiérrez
  • 2. NodeJS • Server side JavaScript • Platform built over Chrome’s v8 • Event driven (asynchronous) • Applications • Data-intensive (efficiency) • Real-time (websockets)
  • 4. npm • node package manager • express (routing) • socket.io (websockets) • mongo (database drivers) • ...
  • 5. Application stack • HTTP server (or TCP-socket or websockets) • Router • Request handlers • Handle data received • View logic
  • 6. HTTP server var http = require("http"); http.createServer(function(request, response) {   response.writeHead(200, {"Content-Type": "text/plain"});   response.write("Hello World");   response.end(); }).listen(8888);
  • 7. TCP server var net = require('net'); var server = net.createServer(function (socket) { socket.write('Echo serverrn'); socket.pipe(socket); }); server.listen(1337, '127.0.0.1');
  • 8. Modules server.js var http = require("http"); function start() {   function onRequest(request, response) {     console.log("Request received.");     response.writeHead(200, {"Content-Type": "text/plain"});     response.write("Hello World");     response.end();   }   http.createServer(onRequest).listen(8888);   console.log("Server has started."); } exports.start = start; index.js var server = require("./server"); server.start();
  • 9. Router and handlers • You can program the routes based on request.url var server = require("./server"); var router = require("./router"); var requestHandlers = require("./requestHandlers"); var handle = {} handle["/"] = requestHandlers.start; handle["/start"] = requestHandlers.start; handle["/upload"] = requestHandlers.upload; server.start(router.route, handle); • I recommend using express (Sinatra like)
  • 11. Websockets • Canal de comunicación full duplex (bidireccional y a la vez) sobre TCP • No hay cabeceras HTTP! (menos overhead) • Aplicaciones que requieren interacciones en tiempo real • URL tipo ws://
  • 12. socket.io • Websockets library • Fallbacks • Flash • AJAX long polling • AJAX multipart streaming • Forever iframe • JSONP polling
  • 13. socket.io support Desktop • Internet Explorer 5.5+ • Safari 3+ • Google Chrome 4+ • Firefox 3+ • Opera 10.61+ Mobile • iPhone Safari • iPad Safari • Android WebKit • WebOs WebKit
  • 14. socket.io example Server var io = require('socket.io').listen(80); io.sockets.on('connection', function (socket) { socket.emit('news', { hello: 'world' }); socket.on('my other event', function (data) { console.log(data); }); }); Client <script src="/socket.io/socket.io.js"></script> <script> var socket = io.connect('http://localhost'); socket.on('news', function (data) { console.log(data); socket.emit('my other event', { my: 'data' }); }); </script>
  • 15. References • http://nodejs.org/ • http://www.nodebeginner.org/ • https://npmjs.org/ • http://socket.io/ • http://www.nodecloud.org/
  • 16. Let’s do some fucking code!!!

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n