[Tutor] Question about socket connections

Joel Ricker joel@prettyhipprogramming.com
17 Sep 2002 00:55:00 -0400


  My recent project in python has been to write two programs, one is a
server for playing card games, while the other will be a client for
playing the game with other connected clients.

  I'm at the point now that I'm trying to decide exactly what messages
should be passed between the server/client and how they should be
passed.  I figure that there'll will probably be two types of messages:
either a message is sent by the client and a response is immediately
needed (as in client: "is it ok to play this card?", server: "yes") and
those that are generated by either the server itself or another
connected client (maybe an instant message or a response to the
opponent's move).

  Since reading from a socket will block until a message is read, my
thinking is that I can start a thread that does nothing but read off
messages from the server and sticks them into a priority queue.  Then
when the client has time, it can process those messages.  That sounds
good for the messages that originate from outside of the client, but
what about messages that the client sends itself and needs a response
too?  Maybe a I can establish a unique key for the request and then have
the client look through the priority queue for a response? This seems a
little complex for what I'm doing and Python has taught me to be
suspicious of complex scripts :)  Any other ideas for this sort of thing
or am I on the right track?

  Thanks
  Joel