如果要实现服务器端,则要查找的超时是连接套接字的超时,而不是主套接字的超时。换句话说,连接套接字对象还有另一个超时,这是socket.accept()方法的输出。因此:sock.listen(1)connection, client_address = sock.accept()connection.settimeout(5) # This is the one that affects recv() method.connection.gettimeout() # This should result 5sock.gettimeout() # This outputs None when not set previously, if I remember correctly.如果实现客户端,那将很简单。sock.connect(server_address)sock.settimeout(3)