1 / 19

Node.JS

Node.JS. Proyecto Redes de Computadores Sem 1 2014. Motivación del grupo. I nteresa observar como funcionan los protocolos tcp / udp y http del lado del servidor. P oder mostrar como hacer nuestro propio servidor http. ¿Qué es Node.JS.

Download Presentation

Node.JS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Node.JS Proyecto Redes de Computadores Sem 1 2014

  2. Motivación del grupo • Interesa observar como funcionan los protocolos tcp/udp y http del lado del servidor. • Poder mostrar como hacer nuestro propio servidor http

  3. ¿Qué es Node.JS • Entorno de programación en la capa del servidor basado en el lenguaje de programación Javascript, con I/O de datos en una arquitectura orientada a eventos y basado en el motor Javascript V8. • Creado por RyanDahl en 2009 • Sistemas Operativos compatibles: Windows, Mac OS X, Linux, Solaris, FreeBSD, OpenBSD, webOS

  4. ¿Con que finalidad se crea Node.JS? • Nace con la idea de poder manejar dos o más cosas a la vez • Es por esto que se caracteriza por tener I/O no bloqueantes, y programación asíncrona.

  5. ¿Cuándo ocupar Node.js? • Para aplicaciones que necesitan muchos requerimientos hacia el servidor (unos miles) sin mucho costo de procesamiento. • Para aplicaciones que necesitan subir archivos demasiado grandes. • Cuando se necesita compartir código entre el cliente y el servidor (JavaScript)

  6. ¿Cuándo no ocupar Node.JS? • Nunca ocupar Node.js cuando se deben procesar muchos datos del lado del servidor. • En este caso es preferible ocupar un sistema basado en multi-hilos

  7. Algunos Ejemplos • Como crear un Socket TCP (server side) • Como crear un Socket UDP (server side) • Como configurar Headers en HTTP • Como crear un simple servidor HTTP con el paquete ‘Express’

  8. Socket TCP var net = require('net'); var HOST = 'localhost'; var PORT = 12345; net.createServer(function(sock) { // We have a connection - a socket object is assigned to the connection automatically console.log('CONNECTED: ' + sock.remoteAddress +':'+ sock.remotePort); // Add a 'data' event handler to this instance of socket sock.on('data', function(data) { console.log('DATA ' + sock.remoteAddress + ': ' + data); // Write the data back to the socket, the client will receive it as data from the server sock.write('Yousaid:' + data ); }); // Add a 'close' event handler to this instance of socket sock.on('close', function(data) { console.log('CLOSED: ' + sock.remoteAddress +' '+ sock.remotePort); }); }).listen(PORT, HOST); console.log('Server listeningon ' + HOST +':'+ PORT);

  9. Demostración

  10. Socket UDP

  11. Demostración

  12. Headers

  13. Demostración

  14. Server HTTP con paquete Express var http = require('http'); varexpress = require('express'); varbodyParser = require('body-parser') varapp = express(); app.use(bodyParser.urlencoded({ extended: true })); app.set('viewengine', 'ejs'); app.set('views', __dirname + '/views'); app.use(bodyParser.json()); app.get('/', function (req,res) { console.log('nueva conexión establecida'); res.sendfile('hello.html'); });

  15. Server HTTP con paquete Express //Continuación app.get('/PhysicsLab.jar',function(req, res){ console.log('jarsended'); res.sendfile('views/PhysicsLab.jar'); }); app.get('*',function(req, res){ res.send('<b> Not Found </b>',404); }); app.post('/',function (req, res) { varinfo = {firstname: req.body.FirstName, lastname:req.body.LastName}; res.render('response',{firstname: req.body.FirstName, lastname:req.body.LastName}); console.log(info); }); app.listen('5000');

  16. Demostración

  17. ¿Quienes usan Node.js? • Microsoft • Google • DuckDuckGo • Linkedln • Walmart • Paypal • Yahoo • Y muchos más …..

  18. El siguiente podrías ser Tu!!

  19. Bibliografía • http://nodejs.org/ • http://en.wikipedia.org/wiki/Node.js • https://medium.com/@edwardoregan/why-node-js-matters-bb49dbf688af • http://devopsangle.com/2013/04/01/the-birth-of-node-where-did-it-come-from-creator-ryan-dahl-shares-the-history/ • http://stackoverflow.com/questions/5062614/how-to-decide-when-to-use-node-js

More Related