0

When I execute a program that uses bind() for second time in the same port, I obtain EADDRINUSE.

I don't want implement setsockopt() for reuse the socket. I want "clear" the used sockets used in used ports before execute my program.

More information: Linux OS.

Rob
  • 99
  • 1
  • 9
  • possible duplicate of [Error: Address already in use while binding socket with address but the port number is shown free by \`netstat\`](http://stackoverflow.com/questions/5106674/error-address-already-in-use-while-binding-socket-with-address-but-the-port-num) – edmz Jan 27 '15 at 19:49

1 Answers1

0

I would say you aren't cleaning up the socket(s) correctly and, so, the kernel will wait for further data to arrive (TIME_WAIT) and discard it (RST). If you do that successfully, you will be able to reuse the port immediately after with no need to "force" that through setsockopt.

Therefore, it is not possible to do but via setsockopt since you need to explicitly tell the kernel that such behavior has to be stopped.

edmz
  • 8,220
  • 2
  • 26
  • 45