与我的上一篇文章相关(不知何故被标记并关闭),我编写了一些代码来为我的 python TCP 侦听器的命令处理程序创建一个线程。基本上发生的是我发送了一些数据,然后它进入了 TCP 连接器。然后 TCP 连接器创建另一个进程并将通过该进程接收到的数据发送到命令侦听器中的函数。我不知道发生了什么事。请帮忙!
import socket
import sys
import errno
from multiprocessing import Process, Queue # @UnresolvedImport
import CommandHandler
class tcpconnection:
def tcp(self):
data = ''
q = Queue()
p = Process(target=CommandHandler.CommandHandler.commands(), args=(self, data))
#
HOST = '' # Symbolic name meaning all available interfaces
PORT = 9999 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
print('Connected by', addr)
while True:
data = conn.recv(1024)
p.start()
p.join()
if not data: break
conn.send(data)
conn.close()
说:
p = Process(target=CommandHandler.CommandHandler.commands(), args=(self, data))
TypeError: unbound method commands() must be called with CommandHandler instance as first argument (got nothing instead)