Monday, January 30, 2012

Socket.Io

Socket.IO aims to make realtime apps possible in every browser and mobile device, blurring the differences between the different transport mechanisms. It's care-free realtime 100% in JavaScript.

We can create realtime application with the use of socket.io . i have used this with my node.js server to create my app . In simple language what socket.io do . I am taking a simple daily life exmple to explain . 

Example - what is socket.io  ?
suppose you are traveling in the bus from New Delhi to Noida . you just board on bus after travelling little you ask conductor is Noida come ? . conductor say no  . after some time you again ask , is noida come ?
conductor said no . and you keep asking to conductor like this . and conductor obviously annoyed at some time .and now imagine if everyone on bus keep asking for their respective stations. this is pretty obvious he will annoy and shout . if same thing happen with server, it may crash. So what we need . that a person who would board on the bus tell conductor in advance that whenever bus arrive to Noida station just tell me . whenever that station come , conductor give a message to all, who so ever is interested just step down from bus. simple.
Same thing we want with sever , whenever a client send request to server it make a bidirectional connection with it which will not going to close after the desired event happen. so its like a tunnel. 
e.g if client want Rss feed of some foo bar website . client just once need to connect with server, whenever server got any new feed it just broadcast to user who is interested  in that feed without opening and closing connection again again . its a persistence connection between client and server. 

why we need socket.io ?
 yes why we need socket.io , sever and client request responses also handle by ajax , but why socket.io.
because we need a persistence connection between client and server. Most of the time wasted in opening and closing connection . why we need to close connection if we want regular news feed .now it make sense . if any client server req res cycle takes 300ms to perform one job . only 100ms it take to exchange data, other 200ms used in opening and closing the connection . This much waste of time it matters on internet . 

No comments:

Post a Comment