Game Development Reference
In-Depth Information
When we create an instance of the WebSocket class in JavaScript, the browser at-
tempts to establish the persistent socket connection with the server. The first thing
that happens is that the browser sends an HTTP request to the URI specified in the
WebSocket constructor. This request contains an upgrade header, specifying that it
wishes to upgrade the connection to using the WebSocket protocol. The server and
the browser then perform a typical handshake, which, for the purposes of this topic
will not be explained in any great detail. If you're interested in implementing your own
backend server application to handle this low-level handshake, you can refer to the
official web socket documentation online.
To be brief, the client sends this HTTP request to the server, including a header con-
taining a key, which is a simple text string. The server then hashes and encodes that
string and sends back an HTTP response, which the browser then validates, and ac-
cepts the protocol upgrade if everything is right. If this handshake is successful, the
browser proceeds to instantiate the WebSocket object, which we can then use to
communicate with the server over the same connection.
Search WWH ::




Custom Search