套接字错误的原因是什么?

时间:2022-04-13 22:57:00

I have a complex python (2.7.3) script which is trying to open a socket connection via

我有一个复杂的python(2.7.3)脚本,试图通过它打开套接字连接

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

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?

主机:端口接受连接,因为我已经用nc主机端口手动验证了这一点。那么,我在打开连接到给定端口时出现这个错误的可能原因是什么呢?

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.

我不能也不会发布完整的脚本,因为这个问题太复杂,太不相关了。我只是想知道这个错误的所有可能的原因,以及如何检查和修复它们。

1 个解决方案

#1


25  

You will need to create a new socket object. Maybe self.socket = socket.socket() after closing the previous socket and before connecting.

您需要创建一个新的套接字对象。也许自我。socket = socket.socket .socket()在关闭之前和连接之前。

#1


25  

You will need to create a new socket object. Maybe self.socket = socket.socket() after closing the previous socket and before connecting.

您需要创建一个新的套接字对象。也许自我。socket = socket.socket .socket()在关闭之前和连接之前。