Ejemplo n.º 1
0
 /** Safely disconnects this ClientHandler from the Server */
 public void disconnect() {
   try {
     pool.removeFromAllQueues(this);
     if (game != null) {
       game.endGame(false); // End the game the client was in.
     }
     reader.close();
     writer.close();
     client.close();
     System.out.println("[Server] Debug (ClientHandler) - Client has disconnected.");
     pool.removeClient(name);
     connected = false;
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 2
0
  @Override
  public void run() {
    connected = true;

    while (connected) {
      try {
        String raw = reader.readLine();
        if (raw != null) {
          System.out.println("Received: " + raw);
          parse(raw.split(" "));
        }
      } catch (SocketException e) {
        disconnect();
      } catch (IOException e) {
        e.printStackTrace();
        disconnect();
      }
    }
  }