I have been trying for 2 days to send a list with 40,000 items which each have 3 items inside of them(its just a list in a list). I am trying to get a server to send over the list to a client so they can render it using pygame. unfortuanatly I am bad a research and existing properly so nothing has worked. I have tried pickle and json. I might have done them wrong tho.
/server.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()
/generation.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])
I fixed it. what I did was only send the entire thing at the begging of the connection. I also sent it in small portions. When I transmitted back to every client I only sent the stuff that had changed. This suprisingly worked. took a while.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.