Close a socket externally

Jeremy Bowers jerf at jerf.org
Fri Oct 1 19:25:00 EDT 2004


On Fri, 01 Oct 2004 22:49:28 +0000, drs wrote:
> I have a program which opens a socket server in a thread.  I need for the
> server to listen on the socket for a certain amount of time (say, ten
> seconds or so) and then close it, and am wondering if there is a good way to
> close the socket other than sending it a message from another thread to
> close itself.  That is, I am looking for a way to forcably kill a socket
> from a second thread, not to send it a message to kill itself.

Speaking generally, I would be surprised if this existed, because it would
basically be a security hole. Not quite literally, but it definitely feels
wrong.

The only way to do it that I can think of is for your program to interpose
itself and act as a proxy between the other two. Then you can close it the
*two* sockets anytime you want, for any reason. You could also separate
the proxy part from the control part by leaving a control port open on the
proxy. This has obvious issues, notably bandwidth, but short of major
kernel patching I think this is your choice.

Or, more likely, your architecture needs a bit of restructuring.

I might be wrong, but if I am, I register my surprise in advance. Also, it
is going to be very, very platform specific and you don't mention what
platform you are on.





More information about the Python-list mailing list