title: Python socket exploiting client address and port for response
body: <p>(I have the following code in which I would like to implement a server-side application and to send clients a response:</p>
  
  <pre><code>class client(Thread):
    def __init__(self, socket, address):
       Thread.__init__(self)
       self.sock = socket
       self.addr = address
       self.start()
  
  def run(self):
      request = ''
      while 1:
        data = self.sock.recv(1024).decode() # The program hangs here with large message
        if not data:
           break
        request += data
     print(request, self.addr[1], self.addr[0]))
     message = "test"
     self.sock.send(message.encode())
  
  
  def init_server():
    serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    serversocket.bind((host, int(port)))
    serversocket.listen(5)
    while 1:
        clients, address = serversocket.accept()
        client(clients, address)
    return
  </code></pre>
  
  <p>Now I write a simple client:</p>
  
  <pre><code>client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  client_socket.connect(('localhost', 8000))
  client_socket.send(message)
  request = ''
  while 1:
    data = client_socket.recv(2048).decode()
    if not data:
    break
    request += data
  print(request)
  client_socket.close()
  </code></pre>
  
  <p>The problem now is that the server hangs in <code>recv</code> with a large message. How can I solve it?</p>