title: python sockets multiple messages on same connection
body: <p>My question is more general rather than specific. I want to implement a simple client server application just to deliver <strong>messages</strong> from the client to the server and get acknowledgments back from the server. </p>
  
  <p>I was wondering what do I have to take into consideration when doing so with sockets, do I have to implement my own communication interface and manage the messaging on the same connection or create a new connection on for each message?</p>
  
  <p>(please make assumption that the message for right now is less than BUFFER_SIZE)</p>
  
  <p>The code is something like this:</p>
  
  <p>server.py</p>
  
  <pre><code>server_info = (HOST, PORT)
  sock = socket.socket(family=AF_INET, type=SOCK_STREAM)
  sock.bind(server_info)
  sock.listen(NUMBER_OF_SOCKETS)
  try:
      while True:
          connection, client_address = sock.accept()
          try:
              while True:
                  data = connection.recv(BUFFER_SIZE)
                  print('message received: {data}'.format(data=data))
                  connection.send("ok")
          finally:
              connection.close()
  </code></pre>
  
  <p>client.py</p>
  
  <pre><code>server_info = (HOST, PORT)
  sock = socket.socket(family=AF_INET, type=SOCK_STREAM)
  sock.connect(server_info)
  try:
      print("connection established")
      while True:
          print("Please enter a message you want to pass to the server")
          msg = raw_input()
  
          print('sending "{message}"'.format(message=msg))
          sock.send(msg)
  
          while True:
              data = sock.recv(constants.BUFFER_SIZE)
              print('received "{data}"'.format(data=data))
              break
  
  finally:
      print('closing socket')
      sock.close()
  </code></pre>
  
  <p>this code gives me the ability to receive multiple message on the server side and send multiple messages from the client side. Is it the right way to do it? I had to make 2 infinite loops on the client side in order to do so, what about closing the connection? when I send a 0 byte message both server and client get stuck.</p>
  
  <p>thank you very much!</p>