title: Why does the simple chat Server-Client always give me a BindException?
body: <p>Why does the code below gives the following exception:</p>
  
  <pre><code>java.net.BindException: Address already in use: JVM_Bind
      at java.net.DualStackPlainSocketImpl.bind0(Native Method)
      at java.net.DualStackPlainSocketImpl.socketBind(DualStackPlainSocketImpl.java:106)
      at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:376)
      at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:190)
      at java.net.ServerSocket.bind(ServerSocket.java:376)
      at java.net.ServerSocket.&lt;init&gt;(ServerSocket.java:237)
      at java.net.ServerSocket.&lt;init&gt;(ServerSocket.java:128)
      at chap15.VerySimpleChatServer.go(VerySimpleChatServer.java:42)
      at chap15.VerySimpleChatServer.main(VerySimpleChatServer.java:36)
  </code></pre>
  
  <p>I tried compiling it with netbeans. I created a project and put both classes inside it.
  This is an example of the book "Head First Java", chapter 15</p>
  
  <p>SERVER: </p>
  
  <pre><code>package chap15;
  import java.io.*;
  import java.net.*;
  import java.util.*;
  
  
  public class VerySimpleChatServer
  {
      ArrayList clientOutputStreams;
  
      public class ClientHandler implements Runnable {
          BufferedReader reader;
          Socket sock;
  
          public ClientHandler(Socket clientSOcket) {
              try {
                  sock = clientSOcket;
                  InputStreamReader isReader = new InputStreamReader(sock.getInputStream());
                  reader = new BufferedReader(isReader);
  
              } catch (Exception ex) { ex.printStackTrace(); }
          }
  
          public void run() {
              String message;
              try {
                  while ((message = reader.readLine()) != null) {
                      System.out.println("read " + message);
                      tellEveryone(message);
                  }
              } catch (Exception ex) { ex.printStackTrace(); }
          }
      }
  
      public static void main(String[] args) {
          new VerySimpleChatServer().go();
      }
  
      public void go() {
          clientOutputStreams = new ArrayList();
          try {
              ServerSocket serverSock = new ServerSocket(5000);
              while(true) {
                  Socket clientSocket = serverSock.accept();
                  PrintWriter writer = new PrintWriter(clientSocket.getOutputStream());
                  clientOutputStreams.add(writer);
  
                  Thread t = new Thread(new ClientHandler(clientSocket));
                  t.start();
                  System.out.println("got a connection");
              }
          } catch (Exception ex) { ex.printStackTrace(); }
      }
  
      public void tellEveryone(String message) {
          Iterator it = clientOutputStreams.iterator();
          while (it.hasNext()) {
              try {
                  PrintWriter writer = (PrintWriter) it.next();
                  writer.println(message);
                  writer.flush();
              } catch (Exception ex) { ex.printStackTrace(); }
          }
      }
  }
  </code></pre>