HTML and CSS Reference
In-Depth Information
Handshake Request
Handshake Response
Close connection
Figure 13-1. The websockets messages
While websockets do not provide peer-to-peer communication, as you'll see later in this chapter, the server
can be implemented to route messages from one client to another. Client A can send a message to the server, which
is simply forwarded to Client b. This emulates peer-to-peer messaging while providing control of the routing.
Completing a Handshake
There is a fair amount of handshaking and protocol manipulation that is required to make WebSockets work.
Fortunately, the browser implements the client side protocol for you, making it really easy to write applications
that use WebSockets. The handshaking messages use the HTTP protocol. Once the connection has been
established, the subsequent messages are sent using the websocket protocol.
Several protocol versions have been proposed and implemented by various browsers. The current version
(as of this writing) is version 13, which both Chrome and Firefox support. You can review the specification of the
Version 13 protocol at .
The process starts when the browser sends a handshake request to the server. The handshake request will
consist of multiple lines of text that will be similar to this:
GET /chat HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Host: localhost:8100
Search WWH ::

Custom Search