Esempio n. 1
0
 /**
  * sends a raw message
  *
  * @param message is a string with the message
  */
 public void sendRaw(String message) {
   try {
     writer.write(message);
     writer.newLine();
     writer.flush();
   } catch (SocketException e) {
     System.out.println("[Server] Tried to send message to disconnected client.");
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Esempio n. 2
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();
   }
 }
Esempio n. 3
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();
      }
    }
  }