how to get any available port

Grant Edwards grante at visi.com
Tue Oct 4 16:50:58 EDT 2005


On 2005-10-04, Paul Rubin <> wrote:
> Grant Edwards <grante at visi.com> writes:
>> > Hmm...perhaps he is trying to do a transfer thing like many chat
>> > programs do. Instead of sending large files across a server, you
>> > "Direct Connect" and send the file directly. :shrugs:
>> 
>> So how does that require binding the client end of a TCP connection?
>
> In the nomenclature of some of these applications, that kind
> of transfer is called a client to client connection.  Both
> ends are called clients.

IIRC, we were talking about TCP sockets.  In a TCP connection,
one end is the client (the one that originates the connection),
and the other end is the server (the one that waits for the
connection on a "well-known" port).

The server calls bind()/listen(), and typically the client just
calls connect().  In theory, the client end can call bind() to
control the originating port used for the connection. But,
servers don't care what the orignating port is, so on the
client end bind() is usually skipped since the default
connect() operation will just choose an available port.

-- 
Grant Edwards                   grante             Yow!  It's strange, but I'm
                                  at               only TRULY ALIVE when I'm
                               visi.com            covered in POLKA DOTS and
                                                   TACO SAUCE...



More information about the Python-list mailing list