我不清楚其他unix和bsd是什么样,linux的socket设置了SO_REUSEADDR,只有在已有的bind的socket是TCP_LISTEN的状态下才会报错,具体的可以去看内核代码
你引文的第4项,unpv3原文是
SO_REUSEADDR allows completely duplicate bindings: a bind of an IP address and port, when that same IP address and port are already bound to another socket, if the transport protocol supports it. Normally this feature is supported only for UDP sockets.
This feature is used with multicasting to allow the same application to be run multiple times on the same host. When a UDP datagram is received for one of these multiply bound sockets, the rule is that if the datagram is destined for either a broadcast address or a multicast address, one copy of the datagram is delivered to each matching socket. But if the datagram is destined for a unicast address, the datagram is delivered to only one socket. If, in the case of a unicast datagram, there are multiple sockets that match the datagram, the choice of which socket receives the datagram is implementation-dependent.
netcat不同平台下很可能不一样,linux的nc是做不到绑定统一ip:port的,如果mac下的可以,建议你用strace看一下,再把结果贴出来
另外,希望lz不要老是怀疑和猜测,软件这玩意特别是大部分软件都是开源的情况下还有什么不确定性的话最好自己认真去看看去查查。
【 在 chunhui 的大作中提到: 】
: resuseadd不能解决,而且它说的已经排除了我试的情况,可见端口是本机范围内的不可重用资源貌似是rfc里的约定。等有空我去看一下是否有明确说明。总之,四元组不同就可以区分连接,这个说法有点陷阱。
: SO_REUSEADDR可以用在以下四种情况下。
: (摘自《Unix网络编程》卷一,即UNPv1)
: ...................