Your SlideShare is downloading. ×
Jugando con websockets en nodeJS
Jugando con websockets en nodeJS
Jugando con websockets en nodeJS
Jugando con websockets en nodeJS
Jugando con websockets en nodeJS
Jugando con websockets en nodeJS
Jugando con websockets en nodeJS
Jugando con websockets en nodeJS
Jugando con websockets en nodeJS
Jugando con websockets en nodeJS
Jugando con websockets en nodeJS
Jugando con websockets en nodeJS
Jugando con websockets en nodeJS
Jugando con websockets en nodeJS
Jugando con websockets en nodeJS
Jugando con websockets en nodeJS
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Jugando con websockets en nodeJS

687

Published on

Presentation of websockets usage in nodeJS, in the jsuc3m study group.

Presentation of websockets usage in nodeJS, in the jsuc3m study group.

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
687
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
17
Comments
0
Likes
3
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Transcript

    • 1. Jugando conwebsockets 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)
    • 3. NodeJS architecture
    • 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 servervar 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 servervar net = require(net);var server = net.createServer(function (socket) { socket.write(Echo serverrn); socket.pipe(socket);});server.listen(1337, 127.0.0.1);
    • 8. Modulesserver.jsvar 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.jsvar 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)
    • 10. Templating• ejs• underscore• jade• ...
    • 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 exampleServervar 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!!!

    ×