Game Engine:
from bezel.networking.engine import NetworkedGame, exposeclass GameEngine(NetworkedGame):
def __init__(self, *args, **kwargs):
super(GameEngine, self).__init__(*args, **kwargs)
self.count = 0
@expose
def say(self, something):
return 'Simon says "%s"' % something
@expose
def add(self, num):
self.count += num
return self.count
Client:
#!/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.
flowblok’s blog