[Twisted-Python] How to listen on and connect from same TCP port with Twisted?

Jean-Paul Calderone exarkun at divmod.com
Mon Jan 12 08:35:37 EST 2009


On Mon, 12 Jan 2009 10:23:00 +0100, Alessio Pace <alessio.pace at gmail.com> wrote:
>On Sat, Jan 10, 2009 at 10:24 AM, Alessio Pace <alessio.pace at gmail.com>wrote:
>
>>
>>
>> On Fri, Jan 9, 2009 at 3:29 PM, Jean-Paul Calderone <exarkun at divmod.com>wrote:
>>
>>> On Fri, 9 Jan 2009 15:13:10 +0100, Alessio Pace <alessio.pace at gmail.com>
>>> wrote:
>>>
>>>> On Fri, Jan 9, 2009 at 3:01 PM, Alvin Delagon <adelagon at gmail.com>
>>>> wrote:
>>>>
>>>>  You shouldn't bind your client on a port where your server is listening
>>>>> to.
>>>>>
>>>>
>>>> I'm following what is written in "Peer-to-Peer Communication Across
>>>> Network
>>>> Address Translators" in order to implement TCP hole punching, and they
>>>> suggested to do so..
>>>>
>>>
>>> Are you talking about section 4.2?  If so, try creating the client before
>>> you create the server.  This is a somewhat arbitrary limitation imposed by
>>> your platform's implementation of the BSD socket API.
>>
>>
>> Thanks for the suggestion, I'll try this and let you know.
>>
>
>Well, apparently at least on my Linux box, I still have the same address
>already bound error even if I first do connect() and then listen() using the
>Twisted reactor APIs  (connectTcp(), listenTcp() ).
>
>Any clue?

You might have to create and connect the socket before giving it to Twisted
then.

Jean-Paul




More information about the Twisted-Python mailing list