大部分内容来自stackoverflow上的回答:Socket options SO_REUSEADDR and SO_REUSEPORT, how do they differ? Do they mean the same across all major operating systems? 由于现有的操作系统上的socket都来自BSD socket,且每种操作系统都后续进行了相应的改变.下面先说 BSD socket中的行为,在最后一节单独介绍linux系统下的socket特定行
Welcome to the wonderful world of portability... or rather the lack of it. Before we start analyzing these two options in detail and take a deeper look how different operating systems handle them, it should be noted that the BSD socket implementation
1.setsockopt中参数之SO_REUSEADDR的意义 1.一般来说,一个端口释放后会等待两分钟之后才能再被使用,SO_REUSEADDR是让端口释放后立即就可以被再次使用. SO_REUSEADDR用于对TCP套接字处于TIME_WAIT状态下的socket,才可以重复绑定使用.server程序总是应该在调用bind()之前设置SO_REUSEADDR套接字选项.TCP,先调用close()的一方会进入TIME_WAIT状态 2.SO_REUSEADDR和SO_REUSEPORT SO