I make a bot in python, it should respond to messages from the server, that is, something like this algorithm

  1. We go about our business ..
  2. If the message arrived we process ..
  3. We are engaged further in the affairs

The code is implemented as a class.

class Spider: def connect(self, host, port): self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.connect((host, port)) def run(self): while (1): if self.sock.recv(1024): # Как сделать что бы он не ждал пока придет? #принимаем команду и обрабатываем 

    2 answers 2

    Use asynchronous calls ( asyncore ), or make a few threads and do not suffer.

      I advise you to read about the Twisted framework