Sunday, June 10, 2012

Ajax long polling

At some application the client needs to check frequently that does some data is avialble on server? if yes then server does reponse it to client, for this the client need to do request frequently, which is not good because of performance point of view. So at this case we are using long polling method,

At this method once a client do a request to server for some response and whenever the response is available at server, it forwards to client. So through the Ajax long polling we set the particular timeout, and in that time a connection is being on between the server and client. Server will response the request whenever it gets the data. Overall process is called Ajax long polling.

Socket.io

socket.io is the module for node.js, it is made by using the concept of websocket. In simple words socket.io is the way to talk from client to server and from server to client. Well there is a very popular technology in the market is called websocket which does the same work  but not supported by all browsers, by default the websocket is available into html5.

Socket.io runs in all browser, so what it will do for run application in all browsers. Socket.io first makes the connection by using the websocket. If it's not supported by any browser then it uses another method for make connection. Here is the fallback transports by using socket.io
websocket,
htmlfile,
xhr-polling,(ajax long polling)
jsonp-polling
flash socket

socket.io makes the percistence connection between server and client. It shares the javascript code between server and client.  when the client emit the particular messesage along with keyword on particular event, At the same time in server the function would run which is associated with the same keyword that the browser emitted. Here is the example

CLIENT
socket.emit('doSomeWork', function (){
    ///some work here///
});

SERVER
socket.on('doSomeWork, function (){
        ///some work here///
});

"doSomeWork" is the same keyword which is shared betweent the client and server.

Saturday, June 9, 2012

Node.js's popularity

Why the node.js is so popular.

Node.js is made by using JavasScript language. Now you can write the javascript code into web server through the node.js, now we can share the javascript code between clent and server. Which can not be acheived by other server side language like php, ruby,  python.
As much as we can share the javascript code between client and server, the cost of web application would be less.

Javascript is event driving programming language, which means the block of code would be executed on particular event. The Node.js uses this concept for acheive high scalable server, You can say the work would be done with non-block concept through node.js, which means there the work could be done in parallel way, The  particular program does not wait to finish other particular work for start his/her work.

Node.js uses the chorme's  V8 JavaScript Engine (it compiles and executes the javascript) for increases the performance for particular application which is made by using node.js. On server some time there need to binary data manupulation so Node.js uses v8 javascript engine for it.