Client-side TCP socket receiving "Address already in use" upon connect

Rhamphoryncus rhamph at
Tue Sep 5 03:34:05 CEST 2006

Felipe Almeida Lessa wrote:
> 2006/9/3, Alex Martelli <aleax at>:
> > Reflecting on the OP's use case, since all connections are forever being
> > made to the same 16 servers, why not tweak thinks a bit to hold those
> > connections open for longer periods of time, using a connection for many
> > send/receive "transactions" instead of opening and closing such
> > connections all of the time?  That might well work better...
> Connecting to 16 differente servers per second gives a very poor
> performance, right? There's some overhead in creating TCP connections,
> even on fast networks and computers. Am I right?

I can think of four costs you would invoke by not reusing connections:
1) extra sockets.  This is what the OP experienced.
2) startup/teardown bandwidth.  More packets need to be sent to start
or end a connection
3) startup latency.  It takes some time to create a usable connection.
4) rampup time.  TCP/IP doesn't dump everything on the network as soon
as a connection is opened.  It "feels it out", giving it more, then a
little more, until it finds the limit.  If you're sending multiple
files (small ones especially!) you'll likely hit this.

So yeah, bottom line, it IS faster and more efficient to reuse
connections.  If you're doing a protocol for sending files you'll want
to do it.

Adam Olsen, aka Rhamphoryncus

More information about the Python-list mailing list