[Tutor] Module Thread

w chun wescpy at gmail.com
Thu Oct 27 12:41:07 CEST 2005


On 10/26/05, Joseph Quigley <cpu.crazy at gmail.com> wrote:
> I'm back to my IRC client. I accidentally found the thread module...
>         What will i do to receive and send at the same time via console?
>
> or:
>         Should I forget the idea of a console and start learning GUI which will
> do this for me.


if you want to do it from the ground up, then take Kent's suggestion
and use threading, not thread.  it's much higher-level and has all the
good primitives you need.

if you want to just worry about the server and client bits, yet still
stay rather low-level, then take a look at SocketServer.  You will use
the ThreadingMixIn with the appropriate connection-type server:

if your server is based on establishing and maintaining a connection
for the IRC-chat, then use the TCPServer.  if you just want to pass
individual msgs back-n-forth, then use the UDPServer.  The
ThreadingMixIn allows for the asynchronous behavior (send and receive
at the same time) that you desire.

note that both client and server behave in a very similar way -- both
will be able to send and recv msgs at the same time.  if you're using
UDP, then they may almost be the exact same class (except that the
server will likely be talking to multiple clients) while for TCP, one
has to establish a port binding and sits-n-waits for cxns (server)
while the other initiates cxns (client).

my suggestion *is* to do the console version 1st, then find your
favorite GUI and just "attach" them to your then-completed
client-server classes.  also has Kent has suggested, drop your last
idea.  ;-)

hope this helps!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2006,2001
    http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com


More information about the Tutor mailing list