我的python IRC客户端原型中的管道破裂错误。我试图在互联网上找到此问题的答案,但没有任何帮助。我认为错误在于将数据发送到关闭的端口,但我不知道为什么它总是关闭。[如果您能解决,请帮助我。
控制台打印此:sent password
Process Process-2:
Traceback (most recent call last):
File "/usr/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
self.run()
File "/usr/lib/python3.7/multiprocessing/process.py", line 99, in run
self._target(*self._args, **self._kwargs)
File "irc_client.py", line 46, in connect
send_data("NICK " + nick)
File "irc_client.py", line 21, in send_data
irc.send(bytes(command + "\n", "UTF-8"))
BrokenPipeError: [Errno 32] Broken pipe
Python代码如下:
irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server = "chat.freenode.net" port = 6697 nick = "dakufjfjhn" password = "password" channel = "#T3ST1NG" joined = False irc.connect((server, port)) def ping(): while joined == False: resp = get_response() if "PING" in resp: print("PONG") send_data("PONG " + resp.split(":")[1]) print("PING!!!!!!!!") def send_data(command): irc.send(bytes(command + "\n", "UTF-8")) def get_response(): return irc.recv(1024).decode("utf-8") def receving(): while True: try: resp = get_response() if "PING" in resp: print("PONG") send_data("PONG " + resp.split(":")[1]) print("Got response.") if len(resp) > 0: print(resp) time.sleep(0.5) except: pass finally: pass def connect(): send_data("PASS " + password) print("sent password") time.sleep(0.3) send_data("NICK " + nick) print("sent nick") time.sleep(0.3) send_data("USER TeStEr * * :TeSting server") print("sent user") time.sleep(0.3) send_data("JOIN " + channel) print("joined channel") time.sleep(0.3) irc.send(bytes("PRIVMSG #T3ST1NG :hello\n", "UTF-8")) print("sent message") print("Connected to server.") p1 = multiprocessing.Process(target=receving) p2 = multiprocessing.Process(target=connect) p1.start() p2.start()