TCP port multiplexing exception that is thrown with setsockopt to solve

TCP port multiplexing exception that is thrown with setsockopt to solve

We will happen in his concurrent connections a server time

OSError: [WinError 10048] 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。

If the port is socket使用过, and with the Socket.close () to close the connection, but this time 端口还没有释放, after the process to go through a TIME_WAIT to use, which is quite annoying TNN silver, in order 实现端口的马上复用, can choose setsockopt () function to achieve.

Implement port multiplexing, I am here to give an example TCP port complex with Python, UDP sockets do exactly the same.

We can add the phrase defined port

from socket import 

server = socket()
server.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
server.bind(('127.0.0.1', 8000))
server.listen(5)

This not being given the

Guess you like

Origin www.cnblogs.com/pythonywy/p/11123004.html