[Twisted-Python] Re: How to get an unused port
Martin Geisler
mg at daimi.au.dk
Wed Feb 27 05:45:01 EST 2008
Gabriel Rossetti <mailing_lists at evotex.ch> writes:
> Matthew Glubb wrote:
>> Hi Gabriel,
>>
>> If memory serves me correctly, when calling reactor.ConnectTCP,
>> specify zero for your port, you'll automatically get an unused port
>> from the dynamic range.
>>
> Thank you, unfortunately I tried it and got 0 back :
>
>>>> reactor.connectTCP("localhost", 0, ClientFactory()).port
> 0
>>>> reactor.connectTCP("localhost", 0,
> ClientFactory()).getDestination().port
> 0
You will never want to connect to port 0 -- there is no such port as
far as I know. Instead you can listen on it. The OS will then allocate
a free port for you to listen on.
So I think you have turned things upside down here :-)
--
Martin Geisler
VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multi-Party Computation) to Python. See: http://viff.dk/.
More information about the Twisted-Python
mailing list