コード例 #1
0
  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;
  }
コード例 #2
0
 public void close() throws IOException {
   if (in != null) {
     in.close();
   }
   if (out != null) {
     out.close();
   }
   if (socket != null && !socket.isClosed()) {
     socket.close();
   }
 }
コード例 #3
0
  @Override
  public void run() {
    SOCKET_PORT = String.valueOf(socket.getRemoteSocketAddress());
    dLog.trace("Starting to run server");
    // get all users
    try {
      users = userSvc.getAllUsers();
    } catch (Exception e2) {
      dLog.error("Unable to get all users", e2);
    }
    dLog.trace("Got " + users.size() + " users");

    try {
      while (!exit) {
        out = new ObjectOutputStream(socket.getOutputStream());
        in = new ObjectInputStream(socket.getInputStream());
        dLog.trace("Successfully got input/output streams");

        String inputStr = "";
        out.writeObject("Burrito POS Server Connected. Enter Username: "******"OUTPUT | Burrito POS Server Connected. Enter Username: "******"OUTPUT | Burrito POS Server Connected. Enter Username: "******"INPUT | " + inputStr);
        parent.updateStatus(appendInfo("INPUT | " + inputStr));

        while (!inputStr.equals("exit") && !this.exit) {
          dLog.trace("Exit? " + exit);
          if (tUser.getUserName() == null) {
            tUser.setUserName(inputStr);
            out.writeObject("OK User " + inputStr + ", enter password: "******"OUTPUT | OK User " + inputStr + ", enter password: "******"OUTPUT | Burrito POS Server Connected. Enter Username: "******"Username: "******" | Password: "******"Stored user: "******" | stored pass: "******"OK User verified. Enter command: ");
              dLog.trace("OUTPUT | OK User verified. Enter command: ");
              parent.updateStatus(appendInfo("OUTPUT | OK User verified. Enter command: "));
              auth = true;
            } else {
              tUser.setUserName(null);
              tUser.setPassword(null);
              out.writeObject("ERROR Invalid Credentials. Enter Username: "******"OUTPUT | ERROR Invalid Credentials. Enter Username: "******"OUTPUT | ERROR Invalid Credentials. Enter Username: "******"exit")) {
              out.writeObject("OK Command " + inputStr + " entered. Enter command: ");
              dLog.trace("OUTPUT | OK Command " + inputStr + " entered. Enter command: ");
              parent.updateStatus(
                  appendInfo("OUTPUT | OK Command " + inputStr + " entered. Enter command: "));
            }
          }

          inputStr = (String) in.readObject();
          dLog.trace("INPUT | " + inputStr);
          parent.updateStatus(appendInfo("INPUT | " + inputStr));
        }

        exit = true;
        try {
          dLog.trace("Closing the socket");
          auth = false;
          out.writeObject("Exiting");
          dLog.trace("Exiting");
          parent.updateStatus(appendInfo("Exiting"));
          this.close();
        } catch (Exception e1) {
          dLog.error("Exception in closing socket", e1);
        }
      }
    } catch (Exception e) {
      dLog.error("Exception in SocketManager run", e);
    }
  }