I have used SO_REUSEADDR
to have my server which got terminated to restart with out complaining that the socket is already is in use. I was wondering if there are other uses of SO_REUSEADDR
? Have anyone used the socket option for other than the said purpose?
相关问题
- Multiple sockets for clients to connect to
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Index of single bit in long integer (in C) [duplic
- Equivalent of std::pair in C
The other main use is to allow multiple sockets to
bind()
to the same port on UDP. You might not think that would come up, but sometimes multiple apps may want to listen on broadcast/multicast addresses with a given port number. It also allows one to bind to the wildcard address, while also binding to a specific address. For instance, Apache might bind to *:80 and 10.11.12.13:80For TCP, the primary purpose is to restart a closed/killed process on the same address.
The flag is needed because the port goes into a
TIME_WAIT
state to ensure all data is transferred.If two sockets are bound to the same interface and port, and they are members of the same multicast group, data will be delivered to both sockets.
I guess an alternative use would be a security attack to try to intercept data.
(Source)
For UDP,
SO_REUSEADDR
is used for multicast.(Source)