HTML and CSS Reference
In-Depth Information
Server Sent Events and Web Sockets
AJAX has been an enormously important technique in allowing the creation of rich and dy-
namic web applications. It is worth pausing to consider however that AJAX is still using the
same basic underlying communication protocol that has been used since the beginning of the
World Wide Web: the client (the web browser) sends an HTTP request to the server (a web
server). The web server responds with a synchronous HTTP response. Once the response is
received the communication is considered complete.
Although this technique works well enough in most scenarios, it is not well suited to two
key scenarios:
1. The server wishes to push information to the client. For instance the server may have a
notification that needs to be sent to the client.
2. The client and server wish to hold a long running conversation with many small messages
transferred back and forth. For instance, consider a real time multi-player game: data must
be transferred back and forward to each client on a regular basis as each user performs activ-
ities that affect the other users.
Although both of these use-cases can be supported by HTTP, HTTP is not the optimal pro-
tocol for either of these scenarios, due both to its overheads, and its stateless nature. In this
chapter we will look at the problems HTTP has adapting to these use-cases, and the solu-
tions offered by HTML5.
Before continuing however, it is worth noting that the APIs examined in this chapter are dif-
ferent from all the APIs examined so far. Not only do they rely on the browser adopting the
APIs, they rely on servers implementing these APIs as well, since they do not play well with
most existing web servers or web infrastructure (such as firewalls and proxy servers).
This chapter will not provide working examples due to the fact it is not possible to provide
simple server-side examples.
Search WWH ::

Custom Search