title: Exception with ObjectInputStream
body: <p>I have three classes, the client, the server and the handler (which is going to handle the server connections) as I show below:</p>
  
  <pre><code>// The Client
      public void sendSomePackage() {
          try {
              socket = new Socket("localhost", 54321);
              sos = socket.getOutputStream();
              oos = new ObjectOutputStream(sockOutput);
          } catch (IOException e) {
              e.printStackTrace(System.err);
              return;
          }
  
          // About to start reading/writing to/from socket
  
          try {
              Package package = new Package(100);
              oos.writeObject(pacote);
  
          } catch (IOException e) {
              e.printStackTrace(System.err);
          }
  
          try {
              Thread.sleep(50);
          } catch (Exception e) {
              e.printStackTrace();
          }
  
          // Done reading/writing to/from socket, closing socket.
  
          try {
              sock.close();
          } catch (IOException e) {
              System.err.println("Exception closing socket.");
              e.printStackTrace(System.err);
          }
          //Exiting
      }
  </code></pre>
  
  <p>Now the server class:</p>
  
  <pre><code>// The Server - with a method that just wait for connections
  
      public void waitForConnections() {
          while (true) {
              try {
                  socket = serverSocket.accept();
  
                  // Server:Accepted new socket, creating new handler for it
                  SimpleHandler handler = new SimpleHandler(socket);
                  handler.start();
  
                  // Server:Finished with socket, waiting for next connection
              }
              catch (IOException e){
                  e.printStackTrace(System.err);
              }
          }
      }
  </code></pre>
  
  <p>My handler, which just handle the server connections:</p>
  
  <pre><code>@Override
  public void run() {
      //Handler: Handler run() starting
      while (true) {
          try {
              package = (Package) ois.readObject();
              if (pacote != null) {
                  System.out.println("Package received " + pacote.getSourceid());
              }
          } catch (Exception e) {
              e.printStackTrace(System.err);
              break;
          }
      }
  
      try {
          // SimpleHandler:Closing socket
          sock.close();
          ois.close();
      } catch (Exception e) {
          // Handler: Exception while closing socket, e=" + e);
          e.printStackTrace(System.err);
      }
  
  }
  </code></pre>
  
  <p>The idea is the client send some 'package' object to my server which is going to keep running receiving the 'package' object any time.
  The connection works fine, but in the end of the program an exception is launched, this is the one:</p>
  
  <pre><code>Package received 100
  java.io.EOFException
      at java.io.ObjectInputStream$BlockDataInputStream.peekByte(Unknown Source)
      at java.io.ObjectInputStream.readObject0(Unknown Source)
      at java.io.ObjectInputStream.readObject(Unknown Source)
      at br.ufscar.socket.SimpleHandler.run(SimpleHandler.java:45)
      at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>I already search for something on Google but nothing so far.
  Any idea ?</p>