Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

running program a second time returns EADDRINUSE for bind [duplicate]

Tags:

c

linux

sockets

Possible Duplicates:
Releasing bound ports on process exit
difference between “address in use” with bind() in Windows and on Linux - errno=98

I have a simple server application I'm writing for Linux and it works decently the first time I run it, but for some reason it's not releasing the port on exit. It seems like I have to wait for some kind of timeout before I can rerun the application to get the port. Otherwise I get an EADDRINUSE error on the bind call.

I feel like I must be doing something stupid, but I have been banging my head against the problem for a while and haven't figured it out, so if someone can point me in the right direction that'd be great. I've tried closing the bound and accepted sockets many times, and at different points, but no luck.

like image 776
Kit Westneat Avatar asked Nov 15 '25 15:11

Kit Westneat


1 Answers

Take a look at these questions and answers:

  • difference between "address in use" with bind() in Windows and on Linux - errno=98
  • Closing a listening TCP socket in C
  • Releasing bound ports on process exit
like image 111
Matt Joiner Avatar answered Nov 18 '25 06:11

Matt Joiner