Socket programming design problem

David null at example.net
Thu Dec 22 17:12:09 EST 2005


After programming with Python for a few hours, I've come up with some code:
http://p.shurl.net/3n.  However, now I've realised there's a bit of a
problem with the original design.

I have a number of questions, if anybody could answer I'd be grateful.

a) Big problem, I can't see how to receive from more than one socket at
once.  I need to do this so that data from the TCP connection can be sent
out on the UDP one and vice versa.  Do I need a thread for each, or is
there some other way I can listen on two sockets at once (maybe
non-blocking ones?)

b) If the script dies prematurely, e.g. I mistyped something and Python
throws an exception, it is caught by the generic handler at the bottom. 
However, the socket does not seem to be cleaned up properly, as if I try to
run it again immediately I get an error that it is still in use.  lsof
doesn't show it in use though, which seems weird.  Is there any particular
reason for this?

Thanks,

David



More information about the Python-list mailing list