• Save
GeekCampSG - Nodejs , Websockets and Realtime Web
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

GeekCampSG - Nodejs , Websockets and Realtime Web

on

  • 1,580 views

Talks about how Node.js and Socket.io are changing the way how Realtime apps are being developed today .

Talks about how Node.js and Socket.io are changing the way how Realtime apps are being developed today .

Statistics

Views

Total Views
1,580
Views on SlideShare
1,366
Embed Views
214

Actions

Likes
0
Downloads
0
Comments
2

7 Embeds 214

http://geekcamp.sg 196
http://www.geekcamp.sg 10
http://nodeslide.herokuapp.com 4
https://si0.twimg.com 1
https://www.google.com 1
https://www.google.nl 1
https://www.google.se 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • I agree. But sometimes people want more control .
    Are you sure you want to
    Your message goes here
    Processing…
  • Nice presentation, just want to add one thing, sometimes instead of building real-time applications overselves using socket.io, node.js, etc., we can use hosted services like http://pusher.com/. It's easier to integrated stuff, than to build things and maintain infrastructure, based on my past experience. However, it varies from case to case.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

GeekCampSG - Nodejs , Websockets and Realtime Web Presentation Transcript

  • 1. Node.js ,Socket.io andthe Magic Bhagaban Behera
  • 2. What is Node.js ?Created by Ryan Dahl ( Joyent )Command line tool to run JavascriptBuilt on Top of Google’s V8 Javascript EngineProvides Javascript API for Network and File System . Used tocreate Servers, Networking tools.Event-driven , non-blocking I/O APIsCore written in C/C++ . Supports C/C++ addons.Can handle thousands of concurrent connections with minimaloverhead on a single process.
  • 3. What’s the need ?
  • 4. Node.js - FeaturesReally Lean( 8000 lines of C/C++and 2000 lines of JS )Exceptionally FastEasily Scalable
  • 5. Event-Driven ApproachAnalogy – Bank ReceptionAnalogy - Restaurant
  • 6. The Cost of IOAccessing RAM ~250 CPU cyclesDisk Operations ~41 000 000 CPU cycles Reading a file Writing to a fileNetwork IO ~240 000 000 CPU cycles Database Query HTTP Responses
  • 7. Handling I/O Apache is multithreaded (depending on conf.) Spawns a thread per request (or process) Each request is in its own "box” Blocking IOresult = query(SELECT * FROM ...);print result.id;
  • 8. The Node waySingle thread for your code...but, I/O runs in parallelHandle thousands of concurrent connectionswith a single processNeed to be very careful with CPU-intensivecode
  • 9. Why JavaScript ?• Single Threaded , Asynchronous• Non blocking IO• Ubiquitous• Massive codebase of libraries• One language to rule them all( Full stack )
  • 10. Hello World !HellowWorld.js HellowWorld.phpsetTimeout(function(){ echo(“Hello”);console.log(“World”); sleep(2000);},2000); echo(“World”);console.log(“Hello”);
  • 11. Our own HTTP Servervar http= require(http);var s = http.createServer(function(req,res){res.writeHead(200,{content-type : text/plain}) ; res.end("hello world n");})s.listen(8000);
  • 12. Built-in Modules• File System require(fs);• HTTP Client and Server require(http);• TCP Sockets require(net);• Many more: http://nodejs.org/docs/v0.4.8/api/
  • 13. Express makes HTTP easier• Nodes HTTP module is low level.• Express is a simple framework inspired by Sinatra (Ruby).• InstallingExpress: npm install express• Robust verb-based routing app.get(/about, function(req, res) { });• Templating(with Jade or EJS)• Sessions
  • 14. When to use Node.js ?Realtime AppsCrawlersSingle-page AppsStreamingFile uploadingOnline GamingCollaborationLive SportsLive chatFinancial Applications
  • 15. Getting StartedNode.js: http://nodejs.org/#downloadBuildinstructions: http://bit.ly/egLfzu Mac:brew update && brew install nodenpm, a package manager for Node:curl http://npmjs.org/install.sh | shMany modules at: http://search.npmjs.org/Windows support isnt great.
  • 16. Node PAASNodeJitsuNodesterJoyentHeroku
  • 17. Socket.io
  • 18. Real-time Web
  • 19. HistoryStatic AppsDynamic AppsAjax AppsReal-time Apps
  • 20. HTTP
  • 21. Ajax Polling
  • 22. Long Polling
  • 23. Sockets
  • 24. Websockets / Socket.ioSocket.IO aims to make realtime apps possible in everybrowser and mobile device, blurring the differences between thedifferent transport mechanisms. Its care-free realtime 100% inJavaScript.
  • 25. Show me the codeVisit http://socket.io/#how-to-use for excellent andsimple documentation .
  • 26. Contact me !bhagaban@noisestreet.com / @bhoga