[Twisted-Python] listenTCP(), tcp.Port()
radix at twistedmatrix.com
Mon Apr 2 12:04:02 EDT 2007
On 4/2/07, Matthew Glubb <matt at zgroupplc.com> wrote:
> Hi All,
> I want to create a simple server that listens for data but I do not
> want to specify the port, I want the port to be automatically
> selected based on the currently available ports on the system. Is
> there any way to do this using Twisted?
> Looking at tcp.Port(), it doesn't seem like there is any provision
> for dynamically selecting an available port. Or am I missing something?
The way you do this on unix is by listening on port 0. The port to
listen on will then be dynamically selected by the kernel.
port.getHost().port will give you the port number that was selected.
International Man of Twistery
More information about the Twisted-Python