[Tutor] playing game across internet: suggestions for design?

Alan Gauld alan.gauld at btinternet.com
Mon May 31 09:58:27 CEST 2010


"Alex Hall" <mehgcap at gmail.com> wrote

> I realize that one of us will have to play server and the other
> client, but the roles nake no difference.

Actually since there are only two players in Battleships you
could dispense with a server and do a peer to peer game.

Or you could create a single server and both be clients.
There are several ways to architect this.
You could even make it a web app with cookies to
record which player is which.

> Basically, how might I go about setting up a connection between the
> two computers? Not at the socket level, but how do I tell his game
> that mine is ready to start? How do I decide who is server and who 
> is
> client? Thanks!

If you go for a socket level interaction then you need to
define your own protocol, or message set. There is a basic
example of that in my tutorial in the Network Programming
topic under the AddressBook example.

If the protocol is significant in size - lots of commands - its
best to define the message strings as constants in a shared
module that both client and server can read. Python's string
formatting characters make a useful templating language.

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/tutor/




More information about the Tutor mailing list