[Tutor] sockets, servers, clients, broadcasts...?

Alan Gauld alan.gauld at btinternet.com
Fri Jun 4 22:00:01 CEST 2010


"Alex Hall" <mehgcap at 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.
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...)

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list