The difference between the "address to use" with bind () on Windows and Linux is errno = 98

I have a small TCP server that listens on a port. Although debugging for me is usually used for CTRL-C server to kill the process.

On Windows, I can quickly restart the service, and the socket can be bounced. On Linux, I have to wait a few minutes before bind () returns with success

If bind () does not work, it returns errno = 98, the address used.

I would like to better understand the differences in implementation. Windows is confident that it is more developer-friendly, but I kind of doubt that Linux is doing the “wrong thing”.

My best guess: Linux waits until all possible clients find that the old socket is broken before allowing the creation of new sockets. The only way to do this is to wait for them to time out.

Is there a way to change this behavior during development on Linux? I hope to duplicate the way Windows does it

+1
source share
1 answer

You want to use the option SO_REUSEADDRon a socket on Linux. Relevant man page socket(7). Here is an example of its use. This question explains what is happening.

Here is a duplicate of this answer.

Linux SO_REUSEADDR , . Windows . Windows SO_REUSEADDR . . .

+3

Source: https://habr.com/ru/post/1793340/


All Articles