[Python] Python Socket 编程,OSError: [Errno 98] Address already in use



Python Socket服务器端脚本运行时,端口被占用

Traceback (most recent call last):
  File "s6.py", line 19, in
    tcpSerSock.bind(addr) 
OSError: [Errno 98] Address already in use


在tcpSerSock = socket(AF_INET, SOCK_STREAM)后面加函数

tcpSerSock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1),让端口重用,问题解决。


from socket import *

tcpSerSock = socket(AF_INET, SOCK_STREAM)
tcpSerSock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)

你可能感兴趣的:(Python,python,socket)