WebSockets - Basic Overview and Getting Started - HTML5 Tutorial

WebSockets vs a Regular Web Site

In the original working of the web, the web browser (client software... Firefox, Internet Explorer, etc.) contacts a web server and asks for a web page. Once the web browser loaded the web page, it stopped talking to the server.

Later, with AJAX, the web browser could tell the server, "Hey, I would like to update this section of the web page." Things sped up a little bit, but it was still the web browser requesting something from the web server.

With Comet and other psuedo-push technologies, the web browser and the web server could begin talking with each other, and the web server could send new data that it wanted to send. It worked sort of like this:

 Web Browser: I'm going to keep this line open in case you have some stuff to send me.
 Web Server: Okay. Check on me.
 Web Browser: You got anything yet?
 Web Server: No.
 Web Browser: You got anything yet?
 Web Server: No
 Web Browser: You got anything yet?
 Web Server: Yep, here it is.
 

The difficulty with that technology is that the web browser kept having to ask (in technical terms, the word is poll) the server for new information. With WebSockets, it'll look a bit more like this.

 Web Browser: I'm going to open up this line in case you have some stuff to send me.  Just let me know when you do.
 Web Server:  I'll let you know when I do.
 [ time passes ]
 Web Server:  Browser, I've got something for you!
 

With WebSockets, the web browser and server get to relax a little more. Now you see its power and benefit. Web Sockets will be more efficient and less bandwidth consuming than Comet-based applications.

And the Catch is...

WebSockets are still finishing development. And older browsers won't get an automatic upgrade. Web sites that choose to use WebSockets will have to use plug-ins or fallback software to accomplish the same goal because while Internet Explorer 9 might support WebSockets, chances are Internet Explorer 8 won't. Nothing is ever perfect!

WebSockets Resources and Links

Return to HTML5 : An Interactive Introduction to HTML 5