WEB SOCKETS
The goal of Web Sockets is to provide full-duplex, bidirectional communication with the server over a single, long-lasting connection. When a Web Socket is created in JavaScript, an HTTP request is sent to the server to initiate a connection. When the server responds, the connection uses the HTTP Upgrade
header to switch from HTTP to the Web Socket protocol. This means that Web Sockets cannot be implemented with a standard HTTP server and must use a specialized server supporting the protocol to work properly.
Because Web Sockets uses a custom protocol, the URL scheme is slightly different. Instead of using the http://
or https://
schemes, there are ws://
for an unsecured connection and wss://
for a secured connection. When specifying a Web Socket URL, you must include the scheme since other schemes may be supported in the future.
The advantage of using a custom protocol over HTTP is that very small amounts of data, unencumbered by the byte overhead of HTTP, can be sent between...