&gt; just close the connection after each message.<p>That is if you don&#x27;t expect to handle more than one connection at a time in a reasonable way. You can certainly do this loop:<p><pre><code>   server_socket = create_and_listen_on_socket(...)
   while True:
      csock = server_sock.accept()
      csock.send(process(csock.recv()))
      csock.close()
</code></pre>
TCP setup and teardown is not too cheap (especially compared to sending UDP packets).