Python套接字发送旧数据

2024-07-04 16:36:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Python中使用子进程套接字模块时遇到了困难。发生的事情是,我将命令发送到客户端,但它不会返回任何内容。直到,我发送另一个命令,并获得前一个命令的输出。我尝试了所有的缓冲区大小,但都没有效果

服务器:

while True:
    shell = input(">> ")
    conn.send(shell.encode())
    data = conn.recv(1600)
    print(data.decode())

客户端:

while True:
    data = sock.recv(1600)
    if not data: break
    data = data.decode()
    commd = subprocess.Popen(data, stdout=subprocess.PIPE, shell=True)
    out, err = commd.communicate()
    sock.send(out)
print("Exiting because no data")

Tags: 命令sendtrue客户端datashelloutconn

热门问题