On 6/4/10, Alan Gauld <alan.ga...@btinternet.com> wrote:
>
> "Alex Hall" <mehg...@gmail.com> wrote
>
>> connect to you as a client. It appears, though, that I need a loop
>> to
>> have a server make any sense at all, to handle incoming data and
>> connection requests.
>
> You need to listen then process incoming messages then listen some
> more, so yes you will need a loop. Probaqbly an infinite one:
>
> while True:
>      listen()
>      if someQuitMessage:
>         break
>      process()
>> rest of my program on hold. Am I safe to use basic threading to
>> stick
>> the server's loop into a new thread?
>
> For your game you don't need to do that. A single thread should
> suffice.
The idea is to have every instance of the game start up a server (if
it is configured to do so by the user). So when a client connects to
you, you and the client exchange data (ship positions, board size, and
so on), then each move by you sends results to the client and each
move by the client sends results to you. For example, the client fires
at square A1. As soon as that happens, a toople something like
("shell","a1")
is sent to you, the server. You then see if that was a hit or a miss
on one of your ships and inform the user accordingly. Currently, the
game is based on an accelerator table inside a wx Frame, but I think
what I will do is put the calls to server.send() as required in each
function called by the accelerator table. I am not sure how I would
insert this into the server's loop; as it stands, it seems much more
intuitive to have the server spinning its wheels, waiting for things
to happen. Again, I am very new to all this, so maybe there is a
better way, but I do not know how I would put all the game logic into
a huge while loop. Oh, I am using the "toomi" library, which provides
basic client and server classes and seems to do what I need, at least
for now.
> But usually a server's listen loop is the main thread and the
> processing
> goes into the sub threads.
>
>> program be able to talk to the server / will the server be able to
>> talk to my program from its new home in its separate thread,
>
> Look at the example in my tutorial. It doesn't use threads but
> services two separate clients without lockup. (Albeit it doesn't
> care about context...)
What is the link for the tutorial? Also, maybe a bit off topic, what
is a context? I dealt with them a lot in Android programming last
semester, but I still do not get them, and I thought they were just an
Android/Java thing.
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to