0
我試圖在同一時間監聽並向多個套接字發送數據。當我運行該程序,我得到連接錯誤,說:在python中同時運行多個套接字
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 704, in __init__
if sock.getsockopt(SOL_SOCKET, SO_TYPE) != SOCK_STREAM:
OSERROR:[錯誤9]錯誤的文件描述符
的第一個插槽正常啓動,但一旦我嘗試啓動一個新的我得到的錯誤。
class bot:
def __init__(self, host, port):
self.host = host
self.port = port
sock = socket.socket()
s = None
def connect_to_server(self):
self.s = ssl.wrap_socket(self.sock)
self.s.connect((self.host, self.port))
上面是類,然後我運行幾個實例。
def run_bots(bots):
for bot in bots:
try:
threading.Thread(target=bot.connect_to_server()).start()
except:
print(bot.host)
print("Error: unable to start thread")
bots = []
b = bot('hostname.com', 1234)
b1 = bot('hostname1.com', 1234)
bots.append(b)
bots.append(b1)
run_bots(bots)
我不知道該怎麼做。任何人都知道可能是什麼問題?
但是,當我創建一個新的bot類實例時,不要創建一個新的實例嗎? – Marius
它的工作。謝謝 :) – Marius