A magical network client

Game Engine:

from bezel.networking.engine import NetworkedGame, expose

class GameEngine(NetworkedGame):
    def __init__(self, *args, **kwargs):
        super(GameEngine, self).__init__(*args, **kwargs)
        self.count = 0

    def say(self, something):
        return 'Simon says "%s"' % something

    def add(self, num):
        self.count += num
        return self.count


#!/usr/bin/env python
from bezel.networking.client import JSONGameClient

client = JSONGameClient('', 8602)
engine = client.engine
print engine.say('blah')

print 'count + 1 =', engine.add(1)

Missing is the network server (the code for that is fairly standard, but I’ve changed a few things, which may confuse people) – suffice to say that it’s a threading TCP server with automatic Avahi publishing.

Example usage (from the root of the bezel-engine repository):

$ demos/network/main.py &
[1] 9422
$ demos/network/client.py
Simon says "blah"
count + 1 = 1
$ demos/network/client.py
Simon says "blah"
count + 1 = 2

Not yet done:

  • Load testing for the server.
  • Client (player) authentication.
  • A class to discover the servers through avahi.

Life update: Main round offers are coming out tomorrow, so I’m hoping to get one for Sydney Uni. It probably won’t be a BIT or a BCST (Adv), but as long as I get in there and do well, I should be able to transfer fairly easily.

Published in: on January 20, 2009 at 10:27 am  Comments Off on A magical network client  
Tags: , , , , , ,
%d bloggers like this: