socket.recvfrom() & sendto()

Van Gale cgale1 at _remove_home.com
Tue May 8 23:57:52 EDT 2001


"Ron Johnson" <ron.l.johnson at home.com> wrote:

> Since the server can send messages to the client at random and
> irregular interevals, how can the client accept input from the
> user at the same time that it is "stalled" at a select() ?

> The server side I think I understand, at least from the perspective
> of *my* needs: the server sits at a select() until it detects (an)
> incoming message(s) from client(s); it then processes the message,
> sends messages back to the sending client(s) and also possibly other
> clients, then goes back to the select().

I think you are understanding the server side correctly, and there's plenty
of server applications in the Medusa package to use as a base for your
server.  One minor point though, the "sending back to the clients" is also
done through the select.  Data being sent out from one of your connection
objects sits in a buffer and is sent out in chunks each time the select on
the socket says "ready to send".

As for the client side, you will need to structure the code in a different
way.  It depends more on what GUI package you are using (wxPython?, wxQt?,
tkinter?) than how the server is structured.  You might need to use threads,
e.g. a thread handling GUI stuff and another thread handling communications
with the server.  However you end up coding it, you DON'T want
communications with the server to block GUI events.

Look at rpc_client.py in Medusa for an example of coding an asynchat client
(although this doesn't do any GUI stuff).  I haven't looked at any of the
Python games out there to see if any of them would make a good starting
point (even though I'm in the game development business<grin>), but I'd bet
you could find some good starting code there as well.

Van






More information about the Python-list mailing list