03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Given that a server can share GDP implementations, the question is, how should it share?<br />

It's easy enough to ensure that a client sending a datagram can get it to the right destination,<br />

but what happens when it reaches that device? Which client should receive it?<br />

The answer is that a session – a connection between two specific games – must be built in<br />

at this level in TOGS, instead of the RGCP level (which moves up the stack). Hence the<br />

name of this level: game session datagram protocol or GSDP. Each time a client program<br />

sends data using GSDP, the GSDP server adds session information into the GDP packet<br />

that is actually sent. When a GSDP server receives a packet, it interprets that session<br />

information to ensure that the packet is routed to the correct recipient. GSDP also includes<br />

the support for setting up a session.<br />

GSDP is still unreliable: a datagram that is sent may not be received. GSDP also makes no<br />

assumptions about the order in which packets are sent. RGCP, the next layer up in the<br />

stack, adds reliability and conversation enforcement, which is useful for games like<br />

Battleships. GSDP could also be used as the basis of other protocols that add reliability in<br />

different ways for use by different types of application.<br />

16.3.4 BSP – Battleships Protocol<br />

Given that RGCP delivers reliable conversation facilities for use by games, the final task was<br />

to specify the protocols to be used by the Battleships game itself.<br />

I called this protocol Battleships Protocol (BSP). BSP allows you to set up an RGCP session,<br />

and play multiple Battleships games. It supports first-move arbitration, turns as hit requests,<br />

abandoning a game midway through, starting a new game after the previous one was won,<br />

lost, or abandoned, and terminating a game including the RGCP session.<br />

In fact, many of these requirements are generic, and BSP could be split into two layers – one<br />

for two-player multigame sessions, and another for the Battleships game itself.<br />

16.3.5 Test Programs<br />

One of the reasons for splitting up a communications stack into layers is simply to be able to<br />

understand each layer, and to understand the stack as a whole.<br />

So, at each stage, we could rely on the tested aspects of our code being good, and<br />

concentrate debugging activity on the new aspects.<br />

Of course, in real life, the development isn't a one-way cascade. You don't catch all bugs in<br />

your test code, and you can never expect to. Even if you do, you make feature changes at<br />

previously tested levels of the stack. You have to go up and down the stack a few times, and<br />

maintain your test code along with the production code.<br />

It's a fact of life that test code tends to take shortcuts, as you concentrate your efforts on the<br />

production code. The TOGS test code can be found on the supporting website at<br />

www.symbian.com/books.<br />

16.3.6 Pattern Reuse<br />

Reuse is good for software systems: it keeps them small and enhances their reliability. In<br />

<strong>Chapter</strong> 3, it was pointed out that sometimes you can't reuse code: you have to reuse<br />

patterns instead.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!