title: java.io.EOFException when trying to perform java socket operations
body: <p>I'm getting the following exception for the code included below that. <strong>This works fine when the while() loop is excluded</strong>. Why is this?</p>
  
  <pre><code>Oct 6, 2011 1:19:31 AM com.mytunes.server.ServerHandler run
  SEVERE: null
  java.io.EOFException
      at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2552)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1297)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
      at com.mytunes.server.ServerHandler.run(ServerHandler.java:68)
  </code></pre>
  
  <p>Class ServerHandler:</p>
  
  <pre><code>public class ServerHandler extends Thread {
   .
   .
   .
  
  public ServerHandler(...){
  ...
  }
  
  
  public void run(){
  
      try {
  
          os = s.getOutputStream();
          oos = new ObjectOutputStream(os);
  
          is = s.getInputStream();
          ois = new ObjectInputStream(is);
  
          while(true){
  
              msg = (Messenger) ois.readObject(); 
  
              String methodType = msg.getKey();
  
              //validating various data passed from the serialized object
              if(methodType.equals("validateCard")){
  
              } else if(methodType.equals("validatePIN")){
  
              }
  
          }
  
     } catch (SQLException ex) {
          Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
      } catch (ClassNotFoundException ex) {
          Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
      } catch (IOException ex) {
          Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
      } finally{
          try {
              ois.close();
              is.close();
              oos.close();
              os.close();
              s.close();
          } catch (IOException ex) {
              Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
          }
      }
  
  
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Class Server</p>
  
  <pre><code>public class Server{
  
      ...
      ServerSocket ss;
      ...
  
      public static void main(String args[]){
          Server server = new Server();
         server.init();
  
      }
  
      public void init(){
          try {
              System.out.println("Server started...");
  
              ss = new ServerSocket(port);
  
               System.out.println("Listening on " + ss.getInetAddress() + ":" + ss.getLocalPort());
  
              System.out.println("Waiting for clients...");
  
              while(true){
                    Socket incoming_socket = ss.accept(); // returns a Socket connection object if received
                    new ServerHandler(...).start();
              }
  
          } catch (IOException ex) {
              Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
          }
      }
  
  
   }
  </code></pre>