gpt4 book ai didi

python - 通过 python3 套接字发送列表

转载 作者:太空宇宙 更新时间:2023-11-03 21:21:52 28 4
gpt4 key购买 nike

我花了 2 天尝试发送一个包含 40,000 个项目的列表,每个项目内有 3 个项目(它只是列表中的列表)。我正在尝试让服务器将列表发送给客户端,以便他们可以使用 pygame 渲染它。不幸的是,我的研究和存在都不好,所以没有任何效果。我尝试过pickle和json。我可能做错了。

/服务器.py

def threaded_client(conn):
while True:
conn.send(json.dumps(cubes).encode())
def stuffs():
while True:
cubes = Sgeneration.cubes.list
s.listen()
conn,data = s.accept()
if not conn in humans:
humans.append(conn)
start_new_thread(threaded_client,(conn,))
Sgeneration.generate.draw(gameDisplay)
pygame.display.update()
stuffs()

/世代.py

def draw(window):
global cubes
g = s.recv(4096)
g = json.loads(data)

print(type(g))
for x in g.get("a"):
pygame.draw.rect(window,x[2],[(x[0]*distance+offset[0]),x[1]*distance+offset[1],distance,distance])

最佳答案

我修好了。我所做的只是在请求连接时发送整个内容。我也分小份寄了。当我传回每个客户时,我只发送了已更改的内容。这出人意料地奏效了。花了一段时间。

关于python - 通过 python3 套接字发送列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54175598/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com