我使用了SO_REUSEADDR
来使我的服务器在重启时不会抱怨套接字已经在使用中。我想知道:还有其他用途可以用于SO_REUSEADDR
吗?是否有人将该套接字选项用于除此之外的其他目的?
TIME_WAIT
状态以确保所有数据都被传输。SO_REUSEADDR
用于多播。
(来源)More than one process may bind to the same
SOCK_DGRAM
UDP port if thebind()
is preceded by:int one = 1; setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
In this case, every incoming multicast or broadcast UDP datagram destined to the shared port is delivered to all sockets bound to the port.
SO_REUSEADDR
+bind()
。发送方(客户端)bind()
+sendmsg()
或只需使用sendto()
发送消息到接收方。为了进行双向通信,两台计算机都创建一个套接字来接收(因此即使是客户端也像服务器一样)。如果您习惯于 TCP,则肯定会感到困惑。如果您有单独的节点(计算机),则SO_REUSEADDR
无用,因为每台计算机只能有一个侦听器。 - Alexis Wilke