handling remote events

Dear all,

I am writing a small application for a project in Experimental
Economics.
For those who do not know what this is: experimental economics uses
controlled, computerised lab experiments with real subjects, putting
the subject in a game mimicking the situation of interest and
collecting behavioural data about choices made.

Hence, experiments involve the use of a multi-client architecture with
one server, and are sort of online games, with actions taken by
clients - each sitting on a different PC - and computation, data
collection, etc... handled by servers.

My game is a sort of Scrabble, with palyers buying letters and
producing words or extending existing words. I use a pipe to ispell -a
for spellcheck, XMLRPC for the server-client infrastructure, and have
developed all the rules of the game as server functions, called by the
clients, that play in turn. States of players and of words created are
stored in instances of two basic classes, Player and Word, on the
server side.

The command line interface works on a turn-base: clients keep asking
the server whether it is their turn or not, and wait in the meantime,
just receiving updates on the 'board' on other players' actions. When
its turn comes, client i performs its operations (buying letters,
composing words) and then passes to the next player.

I need to know how changes on one client's GUI (eg: update game
status; eg: show waiting screen) can be triggered by remote events,
i.e. by events generated on other clients, and then acknowledged by
the server.
In the CLI this is done this way:

---client code---

while True:
    Active = server.checkstatus(i)
    while Active == 0: #player not
active - keep checking and wait
        Active = server.checkstatus(i)
        otheraction = server.checkaction() #keep checking for
actions by other players
        if otheraction == True:
            print details of otheraction
            refresh state of the game (players, words)
    if Active == 1: #player's
turn starts
        buy letters
        produce words
        pass
        print 'Your turn is over: passing the turn to the following
player...'
        notify server of ownaction
        server.passturn() #tell the
server to send Active to next player.

···

----------------------

What I need is a way of triggering a local GUI event - i.e. 'refresh
statistics' and the like, which triggers the refreshing of the main
window and/or on the popping up of dialogs - from a remote event on
the server. The basic GUI is only updated in case of gathering
statistics - imagine a control deck of a vehicle - but a new dialog
has to pop up when the player's turn comes and he has to make
decisions.

Does anyone have any hints on how to deal with this?

Thanks,

Paolo Crosetto
--------------------------------------------------------------------------------
PhD Student in Economics
DEAS - Department of Economics - University of Milan
--------------------------------------------------------------------------------

Paolo Crosetto wrote:

A couple comments:

I use a pipe to ispell -a for spellcheck

you might want to check out pyEnchant to talk to aspell/ispell, rather than using pipes.

The command line interface works on a turn-base: clients keep asking
the server whether it is their turn or not, and wait in the meantime,

you could do exactly the same with a GUI have the wxPython client use a wxTimer to poll the server to see if it is time to go.

Does anyone have any hints on how to deal with this?

You could also use any of a number of tcp-ip protocals for doing this. It sounds backwards, but if you ran a little server in each client, the Server could make a request to it when it needed to update.

Also, I haven't used Twisted, but I'll bet you could use it to build this kind of thing pretty easily.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Chris,

you might want to check out pyEnchant to talk to aspell/ispell, rather
than using pipes.

I checked it out and it is really much simpler, moreover it solves a
dependency on ispell that was causing troubles on window machines.
Thanks!

> The command line interface works on a turn-base: clients keep asking
> the server whether it is their turn or not, and wait in the meantime,

you could do exactly the same with a GUI have the wxPython client use a
wxTimer to poll the server to see if it is time to go.

Thanks to your suggestion I now have a GUI that is able to display a
'control panel' and on the 'background', i.e. every second or so, is
able to poll the server asking if it's time to go.

The problem with this structure is that I have to define a custom
event to be triggered when the polling on the server returns 'True',
i.e. when it is this client's turn. I find it very hard to do so,
since I can not bind the event to any user-generated action, it must
be running ont he background and simply fire when the server says so.

Code: in the frame __init__ I set up a timer, and bind it to a OnTimer
function.

def OnTimer(self, event):
        if Active == False:
            Active = server.checkstatus(self.i) #checks if it's own
turn.
        else:
            pass

This is triggered every second. I now just need to find a way of
generating an event when 'Active' is set to True, but I am lost on
this.

Paolo

Rather than generating an event, why not use pubsub? I think that's
usually the cleaner way of doing it. Otherwise you'll need to look
into PostEvent and probably create some kind of custom command event.

···

On Sep 14, 9:37 am, Paolo Crosetto <paolo.crose...@gmail.com> wrote:

Chris,

> you might want to check out pyEnchant to talk to aspell/ispell, rather
> than using pipes.

I checked it out and it is really much simpler, moreover it solves a
dependency on ispell that was causing troubles on window machines.
Thanks!

> > The command line interface works on a turn-base: clients keep asking
> > the server whether it is their turn or not, and wait in the meantime,

> you could do exactly the same with a GUI have the wxPython client use a
> wxTimer to poll the server to see if it is time to go.

Thanks to your suggestion I now have a GUI that is able to display a
'control panel' and on the 'background', i.e. every second or so, is
able to poll the server asking if it's time to go.

The problem with this structure is that I have to define a custom
event to be triggered when the polling on the server returns 'True',
i.e. when it is this client's turn. I find it very hard to do so,
since I can not bind the event to any user-generated action, it must
be running ont he background and simply fire when the server says so.

Code: in the frame __init__ I set up a timer, and bind it to a OnTimer
function.

def OnTimer(self, event):
if Active == False:
Active = server.checkstatus(self.i) #checks if it's own
turn.
else:
pass

This is triggered every second. I now just need to find a way of
generating an event when 'Active' is set to True, but I am lost on
this.

Paolo

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

There really isn't a need to use an event. Why not just call a method that does whatever you need done from your timer handler when it's time to go?

···

On 9/14/09 7:37 AM, Paolo Crosetto wrote:

This is triggered every second. I now just need to find a way of
generating an event when 'Active' is set to True, but I am lost on
this.

--
Robin Dunn
Software Craftsman

Robin,

it worked! it was the easiest way, and for some strange reason it had
slipped out of my radar.
Now I have the timer triggering a method [subject to if... condition].
Easy, and I should have thought of it before.

Thank you

···

On 14 Set, 20:41, Robin Dunn <ro...@alldunn.com> wrote:

On 9/14/09 7:37 AM, Paolo Crosetto wrote:

> This is triggered every second. I now just need to find a way of
> generating an event when 'Active' is set to True, but I am lost on
> this.

There really isn't a need to use an event. Why not just call a method
that does whatever you need done from your timer handler when it's time
to go?

--
Robin Dunn
Software Craftsmanhttp://wxPython.org