Game Development Reference
In-Depth Information
This posed a problem in solving real-time communication issues using web servers
and HTTP protocols. For example, in a multiplayer game, the information related
to the user moving its character needs to be broadcast to all users playing the game.
Earlier when we posted the game state to our web server, there was no robust and
scalable solution to communicate this information to the other clients in the game
room. Numerous techniques evolved to solve this problem. The most obvious
solution was that we can write a JavaScript code to request the latest information from
the server, using Ajax each second or once in two seconds, which is called polling .
However, polling is not a scalable solution as it can swamp the web server with an
unlimited number of requests. Even if the server did not have any information to
offer, the server was pinged continuously by browsers. The only scalable solution was
a server push. In this topic, we will briely discuss the two most widely used solutions
that can be implemented with most web servers, and they are as follows:
Long polling
A new W3C standard—WebSockets
Understanding Ajax long polling
Ajax long polling is the most prominent solution for real-time communication.
Let's understand how long polling works:
After a browser opens a web page, it has a JavaScript code that sends
a request to the server.
The server does not respond immediately and waits until it has some new
information to give.
When the new information is available, the server sends it over a
keep-alive session.
The moment the client receives the information, it sends another request.
The important point to note is that in HTTP long polling, if the web page
wants to request other information, then it opens another connection and
does not use the same persistent connection. So, at any time, a maximum of
two connections are opened.
The most prominent implementation is in the XMPP protocol in Bidirectional-streams
Over Synchronous HTTP ( BOSH ), used for chatting over HTTP. The following
screenshot demonstrates long polling in a chat system.
 
Search WWH ::




Custom Search