import socket,time s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(('',0)) port=s.getsockname() s.setblocking(0) lines= while True: try: data, addr = s.recvfrom(1024) if addr not in clients: clients.append(addr) if not lines: for client in clients: s.sendto(lines, client) except: pass s.close()
I have paint application, in which the server sends the co-ordinates to a set of clients. I use the above code for sending, launching on a separate thread. This sends data to each client sequentially. This will cause a delay to the clients at the end of the list. Launching a separate thread for each client has scalability issues. Is there is scalabe way to write the above code maybe using async.io?