[Twisted-Python] TCP: can't redo connectTCP() from same local port if server did not explicitly close connection ??

Alessio Pace alessio.pace at gmail.com
Thu Jan 15 03:44:44 MST 2009


Hi,

I would like to have a client connect via TCP to a server (say, server "A"),
then the client close the connection and connect via TCP to another server
(say, server "B") using the same TCP port that was bound locally while
connecting to "A". And then this done over and over again switching from B
to A to B etc..

The fact is that it all works if both the client and the server do
transport.loseConnection() before the client tries to connect to the other
server from the same local port, instead if *only* the client does
transport.loseConnection(), I obtain:

[Failure instance: Traceback (failure with no frames): <class
> 'twisted.internet.error.ConnectBindError'>: Couldn't bind: 98: Address
> already in use.


which it is strange to me as the next connectTCP() attempt is called in the
connectionLost() method of the client, so the socket should be closed
already.

For the very generous readers, I post at http://pastebin.com/m31b0d911 the
code which can be just executed in this way:

* on a terminal, for the server:  python tcp_listen_connect.py -server

* on another terminal, for the client:  python tcp_listen_connect.py -client
127.0.0.1

Comment/uncomment line number 21 to see the affected behaviour.

Sorry for the "please download and verify" approach, but it's 2 days I'm
struggling with it and I was wondering if there is really something I'm
doing wrong or it's just that it works like that.

Thanks in advance.
Regards,
Alessio Pace.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20090115/f5d71b63/attachment.html>


More information about the Twisted-Python mailing list