title: How to make a simple multithreaded socket server in Python that remembers clients
body: <p>How do I make a simple Python echo server that remembers clients and doesn't create a new socket for each request? Must be able to support concurrent access. I want to be able to connect once and continually send and receive data using this client or similar:</p>
  
  <pre><code>import socket
  
  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  host = raw_input("Server hostname or ip? ")
  port = input("Server port? ")
  sock.connect((host,port))
  while True:
      data = raw_input("message: ")
      sock.send(data)
      print "response: ", sock.recv(1024)
  </code></pre>
  
  <p>I.e. with the server running on port 50000, using the above client I want to be able to do this:</p>
  
  <pre><code>me@mine:~$ client.py
  Server hostname or ip? localhost
  Server Port? 50000
  message: testa
  response: testa
  message: testb
  response: testb
  message: testc
  response: testc
  </code></pre>