About Me

My photo
जिंदगी की परीक्षा में कोई नम्बर नहीं मिलते है लोग आपको दिल से याद करे तो समझ लेना आप पास हो गए....

Saturday, 25 January 2014

Notes on Express JS

Express JS is a web application framework used to develop nodejs application easily.

As Express builds over Connect middleware, it brings in a lot of existing
functionality from Connect. Connect's use method configures the app to utilize
the given middleware handle for the given route, where the route defaults to /. You can see the list of middleware provided by Connect at http://www.senchalabs.org/connect/.

app.use(express.methodOverride());

Method Override enables the faux HTTP method support. This means that if we
would like to stimulate the DELETE and PUT method calls to our application, we can do it by adding a _method parameter to the request.

app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));


app.router provides an enhanced version of Connect's router module. Basically,
this is the component that determines what to do when we use routing methods like app.get. The last middleware, Static, provides a static file server and configures it,serving files from the public directory.


Reference : Socket.IO Real-time Web Application Development

Friday, 24 January 2014

Node.js

Node.js :  The JavaScript web application development platform which is the primary target of socket.io.

Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
                  Node.js uses Google Chrome's JavaScript VM to execute JavaScript applications outside the browser, on the server. Node.js does provide an HTTP Server, which can be used to build web applications.

Ryan Dahl developed Node.js in 2008.In the January of 2008, he came up with the idea of building a small web server based on JavaScript. He was inclined towards JavaScript because it was independent of the OS and came without any I/O APIs. He quit his job and worked on Node.js for 6 months. In November 2009, he presented Node.js in JSConf, and has been working for Joyent since then. 

Node.js is a modular framework with a modern module system from the ground
up. Everything in Node.js is built as modules running in the V8 JavaScript engine. Every functionality in the platform is provided by means of modules. This keeps the platform lean and brings in only that what is required. Having a native module system also helps in keeping our applications modular.

Installation :
1.You can go to http://nodejs.org/ and download the appropriate
distribution for your operating system.
2.You'll find the instructions for installing Node.js using
package manager here:
https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager


Reference : Socket.IO Real-time Web Application Development

Notes on Realtime Web History

Netscape came up with a scripting language called JavaScript
(originally LiveScript), and another small company called FutureWave Software
started working on an animation software called FutureSplash Animator. Later,
both of them became the cause of Java applets almost disappearing from the Web.

FutureWave was acquired by Macromedia in 1996 and they renamed FutureSplash Animator to Flash. Flash, as we all know, went on to rule the Web as the most widely available platform for creating animations, games, video players, and everything interactive, for the major part of the next decade.

In 1999, Microsoft used its iframe technology and JavaScript to update news and
stock quotes on Internet Explorer's default home page (http://home.microsoft.
com). In the same year, they released a proprietary ActiveX extension for IE, called XMLHTTP. This was the era when XML was the "in" thing and everyone wanted to use XML for anything they were doing.

This XMLHTTP component was originally meant to load XML data in the page asynchronously, using JavaScript. It was soon adopted by Mozilla, Safari, and Opera, as XMLHttpRequest (or XHR, for short). But it was with the launch of Gmail (by Google) that the term AJAX (Asynchronous JavaScript and XML)—coined by Jesse James Garrett in an article titled Ajax: A New Approach to Web Applications—became the buzzword in web development.

There are multiple mechanisms to give the feeling of data being pushed from the server to the client. These included Hidden iframe, XHR polling, XHR long polling, and Script tag long polling (or, JSONP long polling).

XHR polling : The first and the easiest to implement is XHR polling, in which the browser keeps polling for data periodically, and the server keeps responding with an empty response unless it has data to send back to the browser. Following an event, such as receiving a mail, or creating/updating a record in the database, the server responds to the next polling request with new data.
                           As you can see, there is a problem with this. The browser has to keep making requests to the server even when there is no data. This causes the server to get and process data even when there is nothing to deliver.
                          One of the solutions to this is to modify the server to piggyback the actual client requests by not only sending the data requested by the client, but also appending additional data that the server has, to send to the browser. The client needs to be modified to understand and act upon the additional incoming data.

As the new data is only sent when there is a client action, it causes delays in the
data reaching the browser. The solution to receiving events quickly while avoiding frequent server queries is long polling.

XHR long polling : In long polling, when the browser sends a request to the server, the server won't respond immediately if it doesn't have data to respond with, and will suspend the request. Once the event occurs, the server closes the suspended request by sending over a response to the client. As soon as the client receives the response, it sends a new request.

HTML5 :
In HTML5,there are two new methods for pushing data from the server to the client. One is Server-Sent Events (SSE) and the other is the full duplex WebSockets.
Server-Sent Events attempts to standardize Comet-like communication across
browsers. In this approach, there is a JavaScript API to create an event source, that is,a stream over which the server can send events. This is a unidirectional protocol. We will still be using the good old XHR. This is a good approach when you don't need full duplex communication; just push updates from the server to client.

The other specification which goes on to implement a full duplex communication protocol for the web applications is WebSockets. In WebSockets, the client initiates a socket connection with the server, which supports this protocol as well. The server and client will send and receive data on this socket connection.

Reference : Socket.IO Real-time Web Application Development