A brief analysis of the reasons
Today in writing a python and HTML5 Websocket instance, the stop run rerun script always prompts the address already exists and is used! Query related documents just know in the socket programming, when the client to the server to send a message, shut down the connection, then if you run the server-side program immediately, will prompt this error:
Copy Code code as follows:
Socket.error: [Errno] Address already
This is because in the TCP/IP termination connection four times, when the final ACK reply is issued, there is a 2MSL time to wait, MSL refers to a fragment in the network the largest survival time, this time is generally 30 seconds, so basically after 60 seconds can reconnect!
Why wait for 2MSL? is because at the end of the ACK reply, the sender can not confirm whether the ACK is normal to the other end, if the other end did not receive an ACK reply, will be sent in 1MSL after the fin fragment. So said the sender wait 2MSL time, that is, it sent an ACK and the other send the fin time, if the time is not again received fin fragments, the sender assumes that the other party has received the ACK reply normally, at this time it will normally close the connection!
Ii. Solutions
If a socket-bound address in Python is in use, an error often occurs.
Under Linux:
Copy Code code as follows:
"Socket.error: [Errno] Address already" is displayed.
Under Windows:
Copy Code code as follows:
"Socket.error: [Errno 10048] is usually used only once per socket address (Protocol/network address/port)."
This is because the socket does not support address reuse by default, and if you want to reuse the need to display settings, that is, call the Setsockop function T before binding allows the socket to allow address reuse: socket.setsockopt (socket. Sol_socket,socket. so_reuseaddr,1)
For example:
Copy Code code as follows:
Self.recsocket = Socket.socket (socket.af_inet, socket. SOCK_DGRAM)
Self.recSocket.settimeout (Check_timeout)
Self.recSocket.setsockopt (socket. Sol_socket,socket. so_reuseaddr,1)
Self.recSocket.bind ((', udp_port)