title: UnknownHostException in Java Client/Server-Programm
body: <p>The class Server: </p>
  
  <pre><code>import java.io.IOException;
  import java.net.ServerSocket;
  import java.net.Socket;
  import java.util.ArrayList;
  import java.util.concurrent.ExecutorService;
  import java.util.concurrent.Executors;
  
  public class Server{
  
      private int port;
      private Socket client;
      private ServerSocket server;
  
      public Server(int port) {
          try {
              this.port = port;
              setServer(new ServerSocket(this.port));
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
          this.start();
      }
  
  
      public void start() {
  
          ArrayList&lt;ClientHandler&gt; clients = new ArrayList&lt;&gt;();
          ExecutorService executor = Executors.newFixedThreadPool(20);
  
  
          System.out.println("Server started...");
          while (true) {
              try {
                  setClient(null);
                  setClient(getServer().accept());
                  if (getClient() != null) {
                      ClientHandler handler = new ClientHandler(getClient());
                      System.out.println("Client connected...");
                      clients.add(handler);
                      executor.execute(handler);
  
                  }
              } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
          }
  
      }
  
      public static void main(String[] args) {
          Server server = new Server(4567);
  
      }
  
      public Socket getClient() {
          return client;
      }
  
      public void setClient(Socket client) {
          this.client = client;
      }
  
      public ServerSocket getServer() {
          return server;
      }
  
      public void setServer(ServerSocket server) {
          this.server = server;
      }
  
  }
  </code></pre>
  
  <p>Now, my Question is, is there a Problem in the class, which causes the UnknownHostException? I already tried to debug, but the problem lies in the class Client <br/></p>
  
  <p>The Class Client: <br/></p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.PrintWriter;
  import java.net.Socket;
  import java.net.UnknownHostException;
  import java.util.Scanner;
  
  public class Client{
  
      private String kennung;
      private Socket server;
      private String host;
      private int port;
  
      public Client(String kennung, String host, int port){
          setKennung(kennung);
          setHost(host);
          setPort(port);
          try {
              setServer(new Socket(this.host, this.port));
  
  
              //Scanner reader = new Scanner(this.server.getInputStream());
              PrintWriter writer = new PrintWriter(getServer().getOutputStream(), true);
              Scanner sc = new Scanner(System.in);
  
              writer.println("The Client");
  
  
              /*while(true){
                  boolean next = reader.hasNext();
                  if (next) {
                      String line = reader.nextLine();
                      if(!line.equals(null)){
                      System.out.println("From another one: " + line);
                      }
  
                  }
                  writer.println(sc.next());
              }*/
  
          } catch (UnknownHostException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } finally {
              if( server != null){
                  try {
                      server.close();
                  } catch (IOException e) {
                      //ignore -&gt; Server getting closed
                  }
              }
          }
  
      }
  
  
  
  
  
      public String getKennung() {
          return kennung;
      }
  
  
  
  
  
      public void setKennung(String kennung) {
          this.kennung = kennung;
      }
  
  
  
  
  
      public Socket getServer() {
          return server;
      }
  
  
  
  
  
      public void setServer(Socket server) {
          this.server = server;
      }
  
  
  
  
  
      public String getHost() {
          return host;
      }
  
  
  
  
  
      public void setHost(String host) {
          this.host = host;
      }
  
  
  
  
  
      public int getPort() {
          return port;
      }
  
  
  
  
  
      public void setPort(int port) {
          this.port = port;
      }
  
  
  
  
  
      public static void main(String[] args) {
          Client testClient = new Client("testClient", "127.0.0.1", 4567);
          System.out.println("Client created");
  
      }
  
  
  
  }
  </code></pre>
  
  <p>And Last, but not least: The Class ClientHandler that implements Runnable and runs a Thread, where I read the input from the client and write it to the server.</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.PrintWriter;
  import java.net.Socket;
  import java.util.ArrayList;
  import java.util.Scanner;
  import java.util.concurrent.ArrayBlockingQueue;
  
  public class ClientHandler implements Runnable {
      public ArrayBlockingQueue&lt;String&gt; messsages;
      Socket client;
  
      public ClientHandler(Socket client) {
          this.messsages = new ArrayBlockingQueue&lt;&gt;(20);
          this.client = client;
  
      }
  
      @Override
      public void run() {
  
          PrintWriter writer = null;
          Scanner reader = null;
          try {
              reader = new Scanner(this.client.getInputStream());
              writer = new PrintWriter(this.client.getOutputStream(), true);
          } catch (IOException e1) {
              // TODO Auto-generated catch block
              e1.printStackTrace();
          }
          String line = "";
  
          while (!line.equals(".bye")) {
  
  
              //System.out.println("Got something? " + reader.hasNext()); 
              line = reader.nextLine();
              if (reader.hasNext()) {
                  if (!line.equals(null)) {
                      System.out.println("Vom Client: " + line); 
  
                  }
              }
              //writer.println("Admin-Message"); // Zum Testen
  
          }
  
  
      }
  } 
  </code></pre>
  
  <p><br/> Thanks to everybody, who helps me with this problem.</p>