HTML5 Guidelines for Web Developers

(coco) #1
9.1 The WebSocket Server 233

However, we will provide a few comments to clarify: Although an HTTP request in-
volves sending several header lines back and forth, WebSockets only use two bytes
for this. The first byte shows the start of a message; the second contains the length
of the message. This is a saving (of bytes transferred and bandwidth) with dramatic
consequences when you have to manage many users accessing the site at short
intervals.


If you want to know more about the details of the WebSocket protocol, read
the relevant Internet Draft on the WHATWG website at http://www.whatwg.org/
specs/web-socket-protocol.

Interesting statistics regarding the advantages of WebSockets in different ap-
plications can be found in the article at http://soa.sys-con.com/node/1315473:
The authors even go so far as to refer to WebSockets as a quantum leap in scal-
ability for the web.


9.1 The WebSocket Server


Client-side support for WebSockets is integrated in modern browsers. But we
are still missing one component: the WebSocket server. Although the protocol
specification is not set in stone at the moment, there is already a surprising selec-
tion of software products available. You can choose a server depending on your
preference, be it Java, PHP, Perl, or Python (of course, all products are still in the
test stage).


For this book, we chose a special solution. With node.js is a JavaScript interpreter
capable of running without a browser. The code developed by Google under the
name V8 is working in the background. Because we used JavaScript exclusively
for all previous programming in this book, it made sense to write the server using
JavaScript as well.


There are currently no finished binary packets of node.js, so the installation re-
quires some manual work. With UNIX-type operating systems, the installation is
usually straightforward; for Windows, you still have to resort to the UNIX emula-
tion cygwin.


For a more detailed description regarding the installation of node.js, see the
project’s website at http://nodejs.org.

NOTE

NOTE
Free download pdf