On Sep 11, 9:44 am, Paolo Crosetto <paolo.crose...@unimi.it> wrote:
> In data sabato 05 settembre 2009 21:47:41, Dennis Lee Bieber ha scritto:
>
> > Much better to just send the token TO the active client (which is
> > responsible for returning it at the end of its turn processing)
>
> Dennis,
>
> I am finally getting my head round this problem. I do have a further question,
> though.
>
> I am using XMLRPC as server. It is quite convenient since it handles all low-
> level network stuff for me. On the other hand, though, it seems I cannot make
> the server actually _send_ anything to the clients; it just sits there and
> waits for calls.

XMLRPC is the wrong tool for this job.

Still, you should be able to make it into something workable, but
however you solve it it's going to be suboptimal, I'd think.  Since
you're a beginner and this is presumably more of a research product
than a polished game, that may be good enough.


> This is rather inconvenient for me, as every time I need to send the clients
> some information (eg, the state of the game) I have to formulate the problem
> as a specific call from each client. This can indeed be done quite easily, but
> the end result is a staggering amount of calls to the server, and high cpu
> usage - this might as well slow down the network in the lab, I guess.

First thing to try is to insert pauses (time.sleep) between client
calls when it's not the client's turn.  You are certainly making these
XMLRPC calls in a busy loop; there's no way the CPU would be maxed out
if you paused between calls.  If you insert (say) a 2-second pause
between these calls the CPU usage will drop dramatically.

This is a turn-based game and presumably turns are going to take
around 20-30 seconds, so I doubt the game would suffer much from a 2-
second lag time.

Of course there's no need for the pause when it's the client's own
turn.


> If you look at the pseudocode you sent me - and I implemented - you see, on
> the clients side, where the -->**** are, that a call to update is made over
> and over again.
>
> -=-=-=-=-=- "Display"
>
> connect to "game"
> ACTIVE = False
> while True:
>         get game data                                ---> *****
>         update console display                  ---> *****
>         ACTIVE = game data == active token
>         if ACTIVE:
>                 get user input
>                 if user input == EndTurn:
>                         ACTIVE = False
>                 send user input
>                 if user input == QUIT:
>                         break
> disconnect from "game"

I think what you'd need is "else: time.sleep(2)" after the "if ACTIVE"
block.


> Is there any way of telling XMLRPC 'send this and this to all clients
> connected'?

No.


> Or should I use another server-side technology?

I suspect any libraries that can do this will be an order of magnitude
more difficult to learn, program, and debug.


> I have no much experience in
> writing network programs - this is my first - and I'd rather not go into
> complicated stuff.

If it were me, I'd just live with the limitations of XMLRPC.

BTW, you mentioned that you plan to add a GUI.  Adding a GUI could
cause similar problems, if you intend for the GUI to be responsive
when it's not the client's turn.  Just an advance warning....


Carl Banks
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to