I have multi-threaded python socket server:
connection, client_address = sock.accept()
And i need to store 'connection' to use for other thread.
How to do that?
I have multi-threaded python socket server:
connection, client_address = sock.accept()
And i need to store 'connection' to use for other thread.
How to do that?
Perhaps a list?
connections = []
connection, client_address = sock.accept()
connections.append(connection)
connection[0] # this is your connection
right, when you use s.accept(), it creates like a subchannel you can talk to that client privatly in. so, if you do this:connections.append(connection)
, you can then select the one in the list you want and goconnections[i].send(str.encode("xyz"))
or, if you just want to send a message to every client, just use sock.send("xyz")
, which will send it to everyone. hope this is helpfull :)