code: public void exit() {
          this.quit = true;
          try {
              if (this.clientSocket != null && !this.clientSocket.isClosed()) {
                  this.clientSocket.close();
                  this.clientSocket = null;
              }
          } catch (final IOException e) {
              LOGGER.log(Level.SEVERE, "Error", e);
          }
      }
docs: Quit.