Operating System - HP-UX
1754414 Members
2706 Online
108813 Solutions
New Discussion

bind port 0 failed with error "AddressInUse"

 
MasthanD
Occasional Contributor

bind port 0 failed with error "AddressInUse"

Hi All,

1. I written a client-server code.

2. The process listens at TCP PORT#2000

3. The client process needs to connect to server process but before connecting to server process, I made attempt to bind() the local address for any of the available ports and for that I tried to bind the address as "tcp://0.0.0.0:0" 

4. Ideally when you attempt to bind the address tcp://0.0.0.0:0, then it should bind it any of the available free port.

5. It should not fail with "Address in use" error.

6. It is not clear to me why bind (tcp://0.0.0.0:0) failed with "AddressInUse" error.

Could you please explain when bind (tcp://0.0.0.0:0) failes with "AddressInUse" error?

Thanks,

1 REPLY 1
Steven Schweda
Honored Contributor

Re: bind port 0 failed with error "AddressInUse"

> 1. I written a client-server code.

   I can't see it.  It's usually easier for me to debug code when I can
see the code.

> 2. The process listens at TCP PORT#2000

   Is that "The process" the _server_?

> 3. The client process needs to connect to server process but before
> connecting to server process, I made attempt to bind() the local address
> for any of the available ports and for that I tried to bind the address
> as "tcp://0.0.0.0:0"

   I don't do much socket programming, so I know nothing, but why is the
client using bind()?  Why not connect()?  See, for example:

      http://www.thegeekstuff.com/2011/12/c-socket-programming/

(Or do a Web search for keywords like, say:
      tcp client server example
and see what you find.)