套接字错误“[Errno 9] Bad file descriptor"的原因可能是什么? [英] What could be the reason for a socket error "[Errno 9] Bad file descriptor"
问题描述
我有一个复杂的 python (2.7.3) 脚本,它试图通过
I have a complex python (2.7.3) script which is trying to open a socket connection via
self.socket.close()
# doing something else
self.socket.connect((host, port))
但我得到的只是以下套接字错误:
but all I get is the following socket error:
error: [Errno 9] Bad file descriptor
host:port
接受连接,因为我已经用 nc 主机端口
手动验证了这一点.那么我在打开与给定端口的连接时出现此错误的可能原因是什么?
The host:port
accepts connections as I have verified this with nc host port
manually. So what could be the possible reasons I get this error for opening a connection to the given port, which actually works?
我不能也不会发布完整的脚本,因为它对于这个问题来说太复杂且无关紧要.我只想知道此错误的所有可能原因,以及如何检查和修复它们.
I cannot and will not post the full script as it is too complex and irrelavent for this question. I just would like to know all possible reasons for this error, and how to check them and fix them.
推荐答案
您将需要创建一个新的套接字对象.可能 self.socket = socket.socket()
在关闭前一个套接字之后和连接之前.
You will need to create a new socket object. Maybe self.socket = socket.socket()
after closing the previous socket and before connecting.
这篇关于套接字错误“[Errno 9] Bad file descriptor"的原因可能是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!