bind error, "Address already in use"

bind error, "Address already in use"

Post by Kevin » Wed, 15 May 2002 03:36:00



Hi,

I got a very simple TCP client/server program.
My program worked fine first time, then it failed
when I tried re-run (use the same port as before)
it within a couple minutes. It's failed to bind.

But, if I waited a few minutes, it will work again.
I am sure I closed all socket descriptors before
exiting out.

My test programs are similar to those two
below.

http://www.netbook.cs.purdue.edu/code/code28_1.cod
http://www.netbook.cs.purdue.edu/code/code28_2.cod

I tried my programs on SunOs and Linux, it behaves
the same. I wonder it's a general problem for all
TCP socket progams or something wrong with my program.
Maybe the OS needs time to release the port back
to the pool?

Does anyone got any ideas?

Thanks!

Kevin W.

 
 
 

bind error, "Address already in use"

Post by Lew Pitch » Wed, 15 May 2002 03:45:22



Quote:>Hi,

>I got a very simple TCP client/server program.
>My program worked fine first time, then it failed
>when I tried re-run (use the same port as before)
>it within a couple minutes. It's failed to bind.

>But, if I waited a few minutes, it will work again.
>I am sure I closed all socket descriptors before
>exiting out.

Well, you've run into a feature of TCP; the local socket won't rebind
during it's 2MSL time unless you use the SO_REUSEADDR socket option.

Lew Pitcher, Information Technology Consultant, Toronto Dominion Bank Financial Group

(Opinions expressed are my own, not my employer's.)

 
 
 

bind error, "Address already in use"

Post by Andrew Giert » Wed, 15 May 2002 04:27:05


 Kevin> Hi,
 Kevin> I got a very simple TCP client/server program.  My program
 Kevin> worked fine first time, then it failed when I tried re-run
 Kevin> (use the same port as before) it within a couple minutes. It's
 Kevin> failed to bind.

you should always set the SO_REUSEADDR option before calling bind() with
a fixed port number for a socket which is going to accept connections.

--
Andrew.

comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
                           or <URL: http://www.whitefang.com/unix/>

 
 
 

1. Help with "bind: Address already in use" errors

Hi,

I use Redhat Linux 6.1 on a Dell i7500 laptop.
I have been trying to hook this machine up to a home LAN, and
have thus been editing some of the /etc files to get it to work.
Now I am getting lots of troubling error in /var/log/messages like

Feb 12 06:19:32 lanina inetd[2951]: auth/tcp: bind: Address already in use

The gist of the message is pretty clear, but I have no idea how
to track down which particular address is already in use, and how
to fix it. Any suggestions?

Thanks,
Charlie
--

Earth System Science, University of California, Irvine CA 92697-3100

2. How can I use TrueType fonts with Dillo browser?

3. error in NAMED/BIND "Address already in use"

4. tape drives for Xenix

5. Getting error: "cpd bind address already in use"

6. ./vi won't execute vi?

7. "bind: Address already in use" error after 2.6 upgrade

8. Making a threadsafe "errno"

9. error: could not bind to "IP" port 80 (Address already in use)

10. TCP/IP, bind() error, "address is already in use?"

11. ftp problem: "bind: Address already in use"

12. Solution to "Address already in use" bind() problem?

13. Identd "bind: Address already in use" messages in /var/log/messages