HTML and CSS Reference
To simply extend the WebSocket Protocol, there is another mechanism, called
Like protocols, extensions are negotiated with a Sec- header. The connecting client
sends a Sec-WebSocket-Extensions header containing the names of the extension
(or extensions) it supports.
■ While you cannot negotiate more than one protocol at a time, you can negotiate
more than one extension at a time.
For example, Chrome might send the following header to indicate that it will accept
an experimental compression extension:
Extensions are so named because they extend the WebSocket Protocol. Extensions
can add new opcodes and data fields to the framing format. You may find it more difficult
to deploy a new extension than a new protocol (or “subprotocol”) because browser
vendors must explicitly build in support for these extensions. You'll probably find it much
vendors to standardize an extension and all users to update their browsers to the version
supporting that extension.
Now that we've examined the essentials of the WebSocket Protocol, let's step through
writing our own WebSocket server. There are many existing implementations of the
WebSocket Protocol; you may choose to use an existing implementation in your
applications. However, you may need to write a new server or modify an existing server
out of necessity or just because you can. Writing your own implementation of the
WebSocket Protocol can be fun and illuminating, and can help you understand and
evaluate other servers, clients, and libraries. Best of all, it can give you new insights on
networking, communication, and the Web.
by Node.js. We chose these technologies simply to limit the code samples in this topic to
development, there is a good chance you will be able to read this code fluently, as well.
reasons why you might choose another language. The fact that WebSocket is a language-
agnostic protocol means you can select any programming language capable of listening
on a socket and create a server.