HTML and CSS Reference
In-Depth Information
The WebSocket API solves this problem by allowing the server to initi-
ate a response to the browser without the browser asking for it.
Updates can now be delivered as they're ready and only when they're
ready, as the following diagram shows.
CLIENT
Server
CLIENT
Server
REQUEST
Response
REQUEST
Response
UPDATE 1
Available
UPDATE 1
Available
REQUEST
Response
Response
UPDATE 1
Received
UPDATE 1
Received
UPDATE 2
Available
UPDATE 3
Available
UPDATE 2
Available
UPDATE 3
Available
Response
UPDATE 2
Received
REQUEST
Response
Response
UPDATE 3
Received
UPDATEs 2 & 3
Received
Time
Time
In a traditional AJAX model,
updates from the server are sent
when the client asks for them. If
the client doesn't request an
update, it sits on the server.
With WebSockets, the server is
in control of sending updates.
They can be sent to the client
as soon as they're available.
Standard
4.0
4.0*
A server for WebSockets: Node.js
Experimenting with WebSockets requires a server. The fol-
lowing example uses Node.js, a new server written using Ja-
vaScript. Download Node.js from http://nodejs.org , and
follow the instructions for installing it on your operating sys-
tem. The server-side files used for the example are ch06/
messaging/server-1.js and ch06/messaging/server-2.js.
10.0
11.0
5.0
*
The WebSocket API is dis-
abled by default in Firefox
4 and 5 and Opera due to a
security concern. It must
be enabled manually.
 
Search WWH ::




Custom Search