Game Development Reference
In-Depth Information
The following screenshot shows two HTTP requests. One lasted for 38.08 seconds.
Don't worry, the server is not slow but whenever the server had new information,
the request was completed. If the server did not have new information, the second
request was in the pending state.
Understanding WebSockets
WebSocket is a new HTML5 feature for clients to communicate without the overhead
of the HTTP protocol. The latest version is RFC 6455 ( http://tools.ietf.org/
html/rfc6455 ). It provides us with full duplex bidirectional communication
between the server and the client, without using any HTTP methods. It has its own
protocol specification and has its own API. It offers the most reliable, robust, scalable,
high-performance solution. The beauty is that the communication can happen over
the same port as HTTP. A WebSocket server can coexist with an HTTP server on the
same port.
Before the communication starts, the client needs to perform a handshake with the
server. The client sends a handshake request. The following sample request is an
HTTP handshake request for an upgrade to the WebSocket protocol. Remember
that the WebSocket server is set up on the same port as the HTTP server; hence, an
upgrade request is important. The following is the sample request:
GET /chat HTTP/1.1
Host: server.multiplayergame.com
Upgrade: WebSocket
Connection: Upgrade
Sec-WebSocket-Key: lIHhbXBsZSBub25jZQ==
Origin: http://multiplayergame.com
Sec-WebSocket-Protocol: game
Sec-WebSocket-Version: 13
 
Search WWH ::




Custom Search