예제 #1
0
  public void update(Observable source, Object object) {
    if (source instanceof Users) {
      if (!this.isDisabled()) {
        try {
          Operations.sendUserNamesList(users.getUserNames(), out);
        } catch (IOException io) {
          logger.error("IO Exception", io);
        }
      }
    }

    if (source instanceof Messages) {
      try {
        Operations.sendMessage((MessageType) object, out);
      } catch (IOException io) {
        if (out != null) {
          try {
            out.close();
          } catch (Exception ioe) {
            logger.error("Failed to close the output stream", ioe);
          }
        }

        logger.error("Impossible to send messages", io);
      }
    }
  }
예제 #2
0
 public void run() {
   try {
     prepareClient();
     logger.info("Starting normal session with " + getClientName());
     while (true) {
       this.receive();
     }
   } catch (IOException ioe) {
     logger.warn("Client " + this + " has been disconnected.");
     this.setDisabled(true);
     users.remove(this);
   } finally {
     try {
       if (s != null && !s.isClosed()) {
         s.close();
         logger.warn("Socket with " + this + " has been closed.");
       }
     } catch (IOException ioe) {
       logger.error("Socket has not been closed.", ioe);
     }
   }
 }