I added only two lines, I flush the output stream, probably not necessary,
but certainly safe, and I close the socket at the end of the socket server
loop. This is a work in progress, as I still don't close the socket from
the Python side.