简体   繁体   English

什么可能是套接字错误的原因“[Errno 9]错误的文件描述符”

[英]What could be the reason for a socket error “[Errno 9] Bad file descriptor”

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. host:port接受连接,因为我已经手动验证了nc host port 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. 我只是想知道这个错误的所有可能原因,以及如何检查和修复它们。

You will need to create a new socket object. 您将需要创建一个新的套接字对象。 Maybe self.socket = socket.socket() after closing the previous socket and before connecting. 在关闭前一个套接字之后和连接之前,可能是self.socket = socket.socket()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM