Hi,<br><br><div class="gmail_quote">On Thu, Jan 15, 2009 at 1:58 PM, Jean-Paul Calderone <span dir="ltr">&lt;<a href="mailto:exarkun@divmod.com">exarkun@divmod.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">On Thu, 15 Jan 2009 11:44:44 +0100, Alessio Pace &lt;<a href="mailto:alessio.pace@gmail.com" target="_blank">alessio.pace@gmail.com</a>&gt; wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
<br>
I would like to have a client connect via TCP to a server (say, server &quot;A&quot;),<br>
then the client close the connection and connect via TCP to another server<br>
(say, server &quot;B&quot;) using the same TCP port that was bound locally while<br>
connecting to &quot;A&quot;. And then this done over and over again switching from B<br>
to A to B etc..<br>
<br>
The fact is that it all works if both the client and the server do<br>
transport.loseConnection() before the client tries to connect to the other<br>
server from the same local port, instead if *only* the client does<br>
transport.loseConnection(), I obtain:<br>
<br>
[Failure instance: Traceback (failure with no frames): &lt;class<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
&#39;twisted.internet.error.ConnectBindError&#39;&gt;: Couldn&#39;t bind: 98: Address<br>
already in use.<br>
</blockquote>
<br>
<br>
which it is strange to me as the next connectTCP() attempt is called in the<br>
connectionLost() method of the client, so the socket should be closed<br>
already.<br>
</blockquote>
<br></div>
This is because the client connection goes into the CLOSE_WAIT state instead<br>
of really closing all the way right away. &nbsp;Google for &quot;tcp state diagram&quot;<br>
and take a look at how a socket can close - notice that of the two paths<br>
there are to get to CLOSED, only one of them goes through CLOSE_WAIT.<br>
<br>
There are ways to change this (on most platforms, you can reduce the amount<br>
of time a socket spends in CLOSE_WAIT before going to CLOSED), but it may not<br>
be a good idea to use them. &nbsp;The CLOSE_WAIT state helps make sure that all<br>
data is delivered to the right TCP connection and not a different, unrelated<br>
TCP connection by accident.<br>
<br>
Jean-Paul</blockquote><div><br>Thank you very much Jean-Paul, this answer my issue. <br><br>And sorry for having doubted of Twisted for a moment ;-)<br><br>Regards,<br>Alessio Pace.<br><br></div></div><br>