HTML and CSS Reference
In-Depth Information
Figure 11-3. Quiz game start screen
For this quiz game, you used a single URL to address events for question , answer , and chat messages and general
messages, but you could easily have used a separate socket for each event type. There are several other tweaks and
enhancements that are beyond the scope of this chapter and whose investigation will remain a follow-up exercise for
the reader (for more details, see http://socket.io ) .
Scaling and Reducing Overhead
When it comes to networking, there are many cases in which what works on a small scale, perhaps between a few local
clients on the same computer or local network, fails miserably when attempted on a larger scale. In the following sections,
you will explore how to reduce the overhead of passing data to a large number of clients, using various methods.
Reducing the Size of Data Transmitted
In the previous examples, you used either raw text or JSON to transmit data. JSON is great because it is humanly readable,
relatively lightweight, and natively supported by JavaScript. However, for a highly connected online game, JSON may not
be lightweight enough. The general premise is that the less data transmitted, the faster they transmit and decode. BSON
and MessagePack seek to improve transmission rates by discarding one of JSON's key features: readability.
BSON
Binary JSON (BSON) is an exchange format used in the MongoDB database to store data. As the name implies, BSON
documents are binary encoded. Many of the core concepts from JSON apply, such as being able to embed complex
data structures inside documents (documents inside documents and arrays inside arrays), but BSON adds some new
data types that do not exist in the JSON specification. Unlike JSON, BSON has discrete data and raw binary data types.
 
Search WWH ::




Custom Search