Example #1
0
 public void disconnect() {
   server.logoff(username);
   try {
     TransportObject disconnAck = new TransportObject(Command.disconnect, ServerReply.OK);
     queueReply(disconnAck);
     mySocket.close();
   } catch (IOException e) {
     System.err.print(e);
   }
 }
Example #2
0
 public void processCommand() {
   TransportObject recv = null;
   try {
     recv = (TransportObject) received.readObject();
   } catch (Exception e) {
     disconnect();
   }
   if (recv == null) disconnect();
   else if (recv.getCommand() == Command.disconnect) disconnect();
   else if (recv.getCommand() == Command.login) {
     TransportObject send = new TransportObject(Command.login, ServerReply.REJECTED);
     queueReply(send);
   } else if (recv.getCommand() == Command.logout) {
     server.logoff(username);
     try {
       server.startNewTimer(new SocketParams(mySocket, received, sent));
     } catch (IOException e) {
       e.printStackTrace();
     }
   } else if (recv.getCommand() == Command.readlog) {
     try {
       server.readlog(username);
     } catch (SQLException e) {
       e.printStackTrace();
     }
   } else if (recv.getCommand() == Command.join) server.joinGroup(this, recv.getGname());
   else if (recv.getCommand() == Command.leave) server.leaveGroup(this, recv.getGname());
   else if (recv.getCommand() == Command.send)
     send(recv.getDest(), recv.getMessage(), recv.getSQN());
   else if (recv.getCommand() == Command.rtt) {
     try {
       DBHandler.addRTT(recv.getRTT(), username);
     } catch (SQLException e) {
       e.printStackTrace();
     }
   }
 }