ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Sometimes, you might notice, you try to rerun a server and bind() fails, claiming “Address already in use.” What does that mean? Well, a little bit of a socket that was connected is still hanging around in the kernel, and it's hogging the port.
What EXACTLY is the meaning of the bold words above, in technical terms?
How come I get "address already in use" from bind()?
You get this when the address is already in use. (Oh, you figured
that much out?) The most common reason for this is that you have
stopped your server, and then re-started it right away. The sockets
that were used by the first incarnation of the server are still
active. This is further explained in ``2.7 Please explain the
TIME_WAIT state.'', and ``2.5 How do I properly close a socket?''.
Yeah, that is mentioned in that beej's guide too, but I just
wanted to understand the reason for the error.
The reason is that in order to insure that all packets pertaining to the given tcp connection which were in transit
at the moment you've called 'close' on the socket, are off the wire, the socket is put in a state which causes it to throw all incoming packets.
This state has a timeout and during this timeout you can't recreate the socket with the same combinaton of address,port.
You can read detailed explanation here: http://www.isi.edu/touch/pubs/infocomm99/infocomm99-web
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.