Пример #1
0
 public void close() throws IOException {
   if (in != null) {
     in.close();
   }
   if (out != null) {
     out.close();
   }
   if (socket != null && !socket.isClosed()) {
     socket.close();
   }
 }
  private boolean sendLoginRequest(String userName, String password) throws Exception {
    boolean result = false;

    try {
      sslsocket = (SSLSocket) factory.createSocket(BURRITOPOS_SERVER_IP, BURRITOPOS_SERVER_PORT);
      in = new ObjectInputStream(sslsocket.getInputStream());
      out = new ObjectOutputStream(sslsocket.getOutputStream());

      String str = (String) in.readObject();
      dLog.trace("Got : " + str);
      out.writeObject(userName);
      str = (String) in.readObject();
      dLog.trace("Got : " + str);
      out.writeObject(password);
      str = (String) in.readObject();
      dLog.trace("Got : " + str);
      dLog.trace("good? " + str.split(" ")[0]);

      // check our input
      if (str.split(" ")[0].equals("OK")) {
        result = true;
      }

      out.writeObject("exit");
    } catch (Exception e1) {
      dLog.error("Exception in sendLoginRequest", e1);
    } finally {
      try {
        dLog.trace("Trying to close input stream");
        if (in != null) {
          in.close();
        }
        dLog.trace("Trying to close output stream");
        if (out != null) {
          out.close();
        }
        dLog.trace("Trying to close socket");
        if (sslsocket != null) {
          sslsocket.close();
        }
      } catch (Exception e2) {
        dLog.error("Exception closing socket", e2);
        throw (e2);
      }
    }

    dLog.trace("Returning result: " + result);
    return result;
  }