1.传输层使用不同协议的两个进程,如一个使用tcp,一个使用udp,则不用设置SO_REUSEADDR,两个进程都会绑定同一ip同一port成功,而且会自动区分收到的网络包是发给哪个进程的。
2.对于传输层使用相同协议(都用tcp或都用udp)的多个进程绑定同一ip同一port,必须使用SO_REUSEADDR才能绑定成功。但是收到的网络包只会传给其中的某一个进程,至于是系统随机选择还是用了什么机制选择的,不清楚,好像是传递给了最后绑定的进程。
3.如果想独占端口不准许别人使用,则使用选项SO_EXCLUSIVEADDRUSE即可。
但是:各平台下用法好像有些不同,下面是摘在ICE中的说明
// Enable SO_REUSEADDR on Unix platforms to allow
// re-using the socket even if it's in the TIME_WAIT
// state. On Windows, this doesn't appear to be
// necessary and enabling SO_REUSEADDR would actually
// not be a good thing since it allows a second
// process to bind to an address even it's already
// bound by another process.
//
// TODO: using SO_EXCLUSIVEADDRUSE on Windows would
// probably be better but it's only supported by recent
// Windows versions (XP SP2, Windows Server 2003).
//