next up previous contents
Next: 5.2 A Note on Up: 5. Client/Server Protocol Previous: 5. Client/Server Protocol   Contents

5.1 A Note on Data Types

We are about to describe the protocol-level details of the socket interface to Player. As such, it is worth making clear two details regarding data types. First, the various messages that are sent between client and server are composed of fields of three different sizes, as listed in Table 5.1. They may be signed or unsigned, but they will always be the same size.


Table 5.1: Data types and their sizes
Type size (in bytes)
byte/character 1
short 2
int 4


The second important detail is that all data on the network is in network byte-order (big-endian)5.1. So, before sending a message to the server, the client must ensure that all multibyte fields (i.e., shorts and ints) are in network byte-order. Analogously, before interpreting any messages from the server, the client must ensure that all multibyte fields are in the native byte-order. Single characters require no special processing.

Most programming languages provide some method for converting from network to native byte-order and back. For example, in C you can use library functions like ntohs() and htons(). On the other hand, Java handles byteswapping on data streams automatically, and Tcl offers a choice of byte-order when using the binary command to marshal and demarshal binary strings.


next up previous contents
Next: 5.2 A Note on Up: 5. Client/Server Protocol Previous: 5. Client/Server Protocol   Contents
2004-06-02