What is it ?
Most of the modern web applications display recently updated data, and to do that they need to get he latest data very frequently. Some of them even include some real-time chat (Gmail Chat, Facebook chat).
That’s the interesting part.
- Pull is pretty dumb. You do a request very frequently and you see if anything new appeared. This consumes some bandwidth, some resources (because server has to check if data has actually changed).
- Push is going back to the source : Once you’ve made the request on the server, it doesn’t reply instantly. It will wait for something before sending anything. So push over HTTP is in fact a pull with a sleeping response. Using push over HTTP is called Comet.
So pushing data isn’t very complex, it just requires a special server to transmit some data (text, html, xml, or image) over an already opened HTTP connection.
Why do we need some special servers ? Because our current servers aren’t build to make people wait. Some geeks made some example of PHP code being able to make some Comet response but they all use looping usleep. If you used it, you would end up totally killing your server with the growing number of clients.
This is the very interesting part of Comet : It doesn’t consumes more resources, it just requires additional server software.
Two types of push
They are two types of push :
- The multiple limited time push requests or long poll mode : You make a request and each time you get the response the connection is closed and you have to make an other pull. It’s easier to implement but you could end up doing a lot of http requests, which means generating quite some data.
- The streaming push mode : You open the connection once, and then data comes asynchronously, and the connection is never closed. If it “accidentally” closes, the client reopens it.
How do do some push enabled web applications
You rethink your software so that it uses the push server.
On PHP, you can use The Ajax Push Engine.
On pure .Net environnement, you can use WCF WsDualHttpBinding to serve data.
You have LightStreamer, a commercial product with a free license. It can be connected with nearly anything (the only unsupported type of server seems to be PHP) or StreamHub which has a very restrictive free license.
Why some people still use Flex ou SilverLight ?
By the way, on flex, silverlight, flash, java applets you can use your own sockets to transmit data. This is a very good solution, there a good chance it will consume less bandwidth. But you have to remember that not using the HTTP protocol can create some problems as some companies block every other protocols on their internet gateways.
W3C is on it !
W3C is thinking about adding a WebSocket specification. This could be a very good thing as it would standardize this non-standardized part of the web.
Push outside the web
Push isn’t a web specific concept. Any instant messaging service (like MSN, Jabber, Yahoo or ICQ) does support push.
Any system supporting sockets enables you to make push enabled applications. If you consider the mobile OSes, they all support socket, so they all support push. Androïd supports push by socket, J2ME supports push by sockets, iPhone supports push by Apple push system or sockets and it seems BlackBerry supports it by the BlackBerry push service or sockets.
Author Florent Clairambault