Let's say I have 2 classes Client and Server
class Client(Thread):
def __init__(self, serv):
Thread.__init__(self)
self.serv = serv
def run(self):
self.serv.in.put("Hi")
class Server(Thread):
def __init__(self):
Thread.__init__(self)
self.in = Queue()
self.out = Queue()
def run(self):
while True:
if self.in.get():
#smth to do
So. I'm creating Server and Client, after that, Client send initiate message in queue to Server and I can send something back, etc.
However, when there are 2 or 3 Clients connected to 1 Server and using one Queue there could be some problems. For example - Server read information from Client 2 and think that it's initiate message from Client 3, etc.
Thus, I want to create new Thread with in Queue and out Queue for each client and send it back after first message. So now, they would communicate with server from this new thread.
Should I create new class with in and out Queues and send it back to Client?
I've never worked with threads, so I just don't know how to do it. I tried to google it, but found only tutorials about creating threads.