title: cast error when inflating a serialized object on server side
body: <p>I am trying to send a serialized Java object from a client to a server via socket, but there is a cast error on the server side and I can't figure out why.
  The Class being serialized is below. (I am using Eclipse, and this class is in both the client 
  package and the server package.)</p>
  
  <pre><code>package client; //it is "package server;" on server side
  
  import java.io.Serializable;
  
  public class Simple implements Serializable {
      public String msg;
      public Simple(){
          msg = "simple";
      }
  }
  </code></pre>
  
  <p>on client side, I did:</p>
  
  <pre><code>Simple obj = new Simple();
  Socket socket = new Socket(hostname, portNum);
  ObjectOutputStream objOut = new ObjectOutputStream(socket.getOutputStream());
  objOut.writeObject(obj);
  objOut.flush();
  objOut.close();
  </code></pre>
  
  <p>on the server side, I did:</p>
  
  <pre><code>//already accepted clientSocket
  ObjectInputStream objIn = new ObjectInputStream(clientSocket.getInputStream());
  Simple anObj = (Simple) objIn.readObject();
  System.out.println("from server: " + anObj.msg);
  objIn.close();
  clientSocket.close();
  </code></pre>
  
  <p>However, I got the error:</p>
  
  <pre><code>Exception in thread "main" java.lang.ClassCastException: client.Simple cannot be cast to server.Simple at server.Server.main
  </code></pre>
  
  <p>I tried something similar with the Server and Client in a single package, and both the serialization and inflation worked. I would really appreciate it if you can help me find out why it doesn't work here.</p>