因为要等待 2 个 MSL 才能最终释放连接,所以如果这个时候程序马上启动,就会出现Address already in use错误。要过 1 分钟以后才可以启动成功。如果你写了一个 web 服务器,崩溃以后被脚本自动拉起失败,需要等一分钟才正常,运维可能要骂娘了。
node1:/root/test#python p2.py
Buffer size [Before]: 16384
Buffer size [Before]: 87380
alter-----------------------------------------------------------------------
16384
87380
Traceback (most recent call last):
File "p2.py", line 15, in <module>
s.bind(ip_port)#绑定地址
File "<string>", line 1, in bind
socket.error: [Errno 98] Address already in use
node1:/root/test#
node1:/root#netstat -na | grep 8080
tcp 0 0 192.168.137.2:8080 192.168.137.1:51321 TIME_WAIT
#s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
#s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 0)