JPery / MJPEGWriter

Lightweight HTTP server to stream your OpenCV processing in C++
MIT License
97 stars 40 forks source link

Enable address reuse https://stackoverflow.com/questions/14388706/how… #22

Open torresclucia opened 2 years ago

torresclucia commented 2 years ago

…-do-so-reuseaddr-and-so-reuseport-differ

The question is, how does the system treat a socket in state TIME_WAIT? If SO_REUSEADDR is not set, a socket in state TIME_WAIT is considered to still be bound to the source address and port and any attempt to bind a new socket to the same address and port will fail until the socket has really been closed. So don't expect that you can rebind the source address of a socket immediately after closing it. In most cases this will fail. However, if SO_REUSEADDR is set for the socket you are trying to bind, another socket bound to the same address and port in state TIME_WAIT is simply ignored, after all its already "half dead", and your socket can bind to exactly the same address without any problem. In that case it plays no role that the other socket may have exactly the same address and port.

https://stackoverflow.com/questions/14388706/how-do-so-reuseaddr-and-so-reuseport-differ

JPery commented 2 years ago

Hi!

First of all, thanks for your PR!

I think you are trying to avoid the error "ERROR on binding:Address already in use.". Is that it?

As they say at https://stackoverflow.com/questions/24194961/how-do-i-use-setsockoptso-reuseaddr, Note than in addition to SO_REUSEADDR, you might need to set SO_REUSEPORT to get the desired behavior, so we will have to include it as well.