More attempts to close the sockets, on both the python side, and added closes
in the catch blocks of the Java code to deal with failures.