Re: Checking if port is in use.

2005-03-19 Thread Peter Hansen
Alex Polite wrote: On lör, mar 19, 2005 at 10:12:10 -0500, Peter Hansen wrote: Alex Polite wrote: You could, for example, bind to a port of "0" and that will auto-assign an available port for you. Does that work in your case? If not, please describe what you are really trying to accomplish. I'm l

Re: Checking if port is in use.

2005-03-19 Thread Grant Edwards
On 2005-03-19, Alex Polite <[EMAIL PROTECTED]> wrote: > > If I try to bind a socket to a port that's already in use I get this > error > > "error socket.error: (98, 'Address already in use')" > > Is there anyway to check in advance if a port i already taken? Yes. Try to bind to the port. If you

Re: Checking if port is in use.

2005-03-19 Thread elbertlev
How about this? try: s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,1) s.bind((HOST, PORT)) except socket.error, e: if e print "address already in use" -- http://mail.python.org/mailman/listinfo/python-list

Re: Checking if port is in use.

2005-03-19 Thread Alex Polite
On lör, mar 19, 2005 at 10:12:10 -0500, Peter Hansen wrote: > Alex Polite wrote: > > You could, for example, bind to a port of "0" and that will > auto-assign an available port for you. Does that work > in your case? If not, please describe what you are really > trying to accomplish. I'm launch

Re: Checking if port is in use.

2005-03-19 Thread Peter Hansen
Alex Polite wrote: If I try to bind a socket to a port that's already in use I get this error "error socket.error: (98, 'Address already in use')" Is there anyway to check in advance if a port i already taken? In general in Python it's not considered good style to "look before you leap". After all