Close resources in tests and in case of Exceptions and use try-with-resources. Close the socket-connection during encrpyting/decrypting as soon as it is not needed any more.