HTML and CSS Reference
In-Depth Information
Chapter 3
The WebSocket Protocol
WebSocket is a network protocol that defines how servers and clients communicate over
the Web. Protocols are agreed-upon rules for communication. The suite of protocols that
comprise the Internet is published by the IETF, the Internet Engineering Task Force. The
IETF publishes Requests for Comments, called RFCs, which precisely specify protocols,
including RFC 6455: The WebSocket Protocol. RFC 6455 was published in December 2011
and contains the exact rules that must be followed when implementing a WebSocket
client or server.
In the previous chapter, we explored the WebSocket API, which allows applications
to interact with the WebSocket Protocol. In this chapter, we take you through a brief
history of the Internet and protocols, why the WebSocket Protocol was created, and how
it works. We use network tools to observe and learn about WebSocket network traffic.
Using an example WebSocket server written in JavaScript with Node.js, we examine how
WebSocket handshakes establish WebSocket connections, how messages are encoded
and decoded, and how connections are kept alive and closed. Finally, we use this
example WebSocket server to remote control several browsers at the same time.
Before the WebSocket Protocol
To better understand the WebSocket Protocol, let's look at some of the historical context
by taking a quick tour to see how WebSocket fits into an important family of protocols.
Protocols are one of the greatest parts of computing. They span programming
languages, operating systems, and hardware architectures. They allow components
written by different people and operated by different agents to communicate
amongst themselves from across the room or across the world. So many of the
success stories in open, interoperable systems are due to well-designed protocols.
Before the introduction of the World Wide Web and its constituent technologies like
HTML and HTTP, the Internet was a very different network. For one, it was much smaller
and, for another, it was essentially a network of peers. Two protocols were and still are
prevalent when communicating between Internet hosts: the Internet Protocol (IP, which
Search WWH ::

Custom Search