Re: how to get any available port

2005-10-05 Thread Steve Holden
[EMAIL PROTECTED] wrote: > Apparently, calling bind() with a zero "port" will choose some available port > number, as demonstrated by this program: > > import socket > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.bind(("", 0)) > print s.getsockname() > > Here's how it behaved over se

Re: how to get any available port

2005-10-04 Thread Cameron Laird
In article <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]> wrote: . . . >Here's how it behaved over several runs: >$ python soc.py >('0.0.0.0', 34205) >$ python soc.py >('0.0.0.0', 34206) >$ python soc.py >('0.0.0.0', 34207) > >I

Re: how to get any available port

2005-10-04 Thread Paul Rubin
"Fredrik Lundh" <[EMAIL PROTECTED]> writes: > Grant Edwards wrote: > > IIRC, you just call bind() with a port number of zero, and then > > use some method-or-other on the bound socket to find out what > > port it's bound to. > > >>> s = socket.socket() > >>> s.bind(("", 0)) > >>> s.getsockaddr() >

Re: how to get any available port

2005-10-04 Thread Fredrik Lundh
Grant Edwards wrote: > IIRC, you just call bind() with a port number of zero, and then > use some method-or-other on the bound socket to find out what > port it's bound to. >>> s = socket.socket() >>> s.bind(("", 0)) >>> s.getsockaddr() ("0.0.0.0", 4711) -- http://mail.python.org/mailman/l

Re: how to get any available port

2005-10-04 Thread Grant Edwards
On 2005-10-04, Paul Rubin <> wrote: > Grant Edwards <[EMAIL PROTECTED]> writes: >> > 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. > So, ther

Re: how to get any available port

2005-10-04 Thread Grant Edwards
On 2005-10-04, Paul Rubin <> wrote: > Mohammed Smadi <[EMAIL PROTECTED]> writes: >> #transmission socket >> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) >> s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) >> s.bind(("",hp_port)) # do some error checking >> ... >> any suggestions fo

Re: how to get any available port

2005-10-04 Thread Grant Edwards
On 2005-10-04, Mohammed Smadi <[EMAIL PROTECTED]> wrote: > On Tue, 4 Oct 2005, Grant Edwards wrote: > >> On 2005-10-04, ncf <[EMAIL PROTECTED]> wrote: >> >> > Hmm...perhaps he is trying to do a transfer thing like many chat >> > programs do. Instead of sending large files across a server, you >> >

Re: how to get any available port

2005-10-04 Thread Fredrik Lundh
Mohammed Smadi wrote: > what else would you do? I am using examples from the web and they all > bind to a port at the localhost before connecting to the remote host. pointers, please. > my code is like this > > #transmission socket > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.se

Re: how to get any available port

2005-10-04 Thread Paul Rubin
Mohammed Smadi <[EMAIL PROTECTED]> writes: > #transmission socket > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) > s.bind(("",hp_port)) # do some error checking > ... > any suggestions for alternative implementation? In this parti

Re: how to get any available port

2005-10-04 Thread jepler
On Tue, Oct 04, 2005 at 05:19:37PM -0400, Mohammed Smadi wrote: > what else would you do? I am using examples from the web and they all > bind to a port at the localhost before connecting to the remote host. [...] the web must be stupider than I thought. Here's how Python's own ftplib connects

Re: how to get any available port

2005-10-04 Thread Paul Rubin
Grant Edwards <[EMAIL PROTECTED]> writes: > > 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. Yes, but if the person was talking about using TCPs s

Re: how to get any available port

2005-10-04 Thread Mohammed Smadi
On Tue, 4 Oct 2005, Grant Edwards wrote: > On 2005-10-04, ncf <[EMAIL PROTECTED]> wrote: > > > 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 ho

Re: how to get any available port

2005-10-04 Thread jepler
Apparently, calling bind() with a zero "port" will choose some available port number, as demonstrated by this program: import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(("", 0)) print s.getsockname() Here's how it behaved over several runs: $ python soc.py ('0.0.0.0', 34

Re: how to get any available port

2005-10-04 Thread Grant Edwards
On 2005-10-04, Paul Rubin <> wrote: > Grant Edwards <[EMAIL PROTECTED]> 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 t

Re: how to get any available port

2005-10-04 Thread Paul Rubin
Grant Edwards <[EMAIL PROTECTED]> 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

Re: how to get any available port

2005-10-04 Thread Grant Edwards
On 2005-10-04, ncf <[EMAIL PROTECTED]> wrote: > 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 conn

Re: how to get any available port

2005-10-04 Thread ncf
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: -- http://mail.python.org/mailman/listinfo/python-list

Re: how to get any available port

2005-10-04 Thread Fredrik Lundh
Mohammed Smadi wrote: > if am using s.bind for a tcp socket. On the client side i dont really > care which socket i use as long as i get an available socket. Is there a > funciton or a way to get an available socket? why are you using bind if you're on the client side? -- http://mail.pyt

how to get any available port

2005-10-04 Thread Mohammed Smadi
hi; if am using s.bind for a tcp socket. On the client side i dont really care which socket i use as long as i get an available socket. Is there a funciton or a way to get an available socket? thanks smadi -- http://mail.python.org/mailman/listinfo/python-list