title: Using TCP Client to send multiple messages in Python
body: <p>I have many TCP clients that needs to send multiple messages to a server. On the server side, I wrote:</p>
  
  <pre><code>def listenConnections():
      thread_recieve = Thread(target=recieveInstruction)
  
      while(1):
          lstn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
          # port = int(sys.argv[1]) # server port number
  
          lstn.bind(('IP', PORT))
  
  
          lstn.listen(5)
  
          global clnt
          (clnt,ap) = lstn.accept()
  
         thread_recieve.start()
  
  def recieveInstruction():
      while (1):
          try:
              message = clnt.recv(1024)
              print message
          except:
              pass
  </code></pre>
  
  <p>So what happens is, every time one client connects he is able to send 1 message and the server reads it. But when another client connects or the same client tries to send another message it doesn't work. The client side is pretty solid, I can't seem to know how to get to use the connection that is created multiple times to be able to receive messages. That is why I tried multithreads, but that didn't work either. Btw, I run listenConnections on a thread also. I do:</p>
  
  <pre><code>def main():
  
      t = Thread(target=listenConnections)
  
      t.start()
  
  main()
  </code></pre>