title: JAVA: Serialization works good on Local Machine but when I do this in LAN it does not output correct
body: <p><strong>I want to send an object having OS Name to a server. This OS Name output should be of PC sending object but it displays OS Name of PC running server..</strong></p>
  
  <p>Here is my code :</p>
  
  <p>//Client : it can send data i.e. object to server
      class Client </p>
  
  <pre><code>{
  
          private Socket socket = null;
  
  
  private ObjectOutputStream outputStream = null;
  
      public Client(String con){
  
  System.out.println("conn value: "+con);
  
  java.util.Timer t = new java.util.Timer();
  
  try{
  
  socket = new Socket(con, 27051);
  
  t.scheduleAtFixedRate(new TimerTask() {
  
   @Override
  
      public void run() {
  
      try {
  
  outputStream = new ObjectOutputStream(socket.getOutputStream());
  
  SI sysinfo=new SI();
  
   outputStream.writeObject(sysinfo);
  
  System.out.println("Sent Data: "+sysinfo.otherInfo());
  
  
  }  catch (Exception se) {
  
     t.cancel();
  
  }
  
   }
   },  0, 1);
  
  }
  
  catch(Exception em)
  
  {
  
    }
  
  }
  
  }
  
  //Server class: should receive data from client
  
  class Server extends SwingWorker&lt;Void,Void&gt;{
  
     Socket csocket=null;  
  
          protected Void doInBackground() throws Exception {
  
  
  
          final ServerSocket ssock = new ServerSocket(27051);
  
  System.out.println("Server Listening..!!");
  
  
        while (true) {
  
             try{
  
            Socket sock = ssock.accept();
  
           new Thread(new Server(sock)).start();
  
             }
  
             catch(Exception e){
  
                 System.out.println("unabke to create socket");
  
             }
  
       }   
  
  
     }
  
        Server() throws Exception{
  
            doInBackground();
  
        }
  
     Server(Socket csocket) {
  
         this.csocket=csocket;
  
         Thread t1=new Thread(r1);
  
     t1.start();
  
     }
  
     Runnable r1=new Runnable()
  
     {
  
     public void run() {
  
       try {  
  
           System.out.println("Run initated");
  
            while(true)
  
         {
  
  
            if(csocket.isClosed())
  
            {
  
  break;
            }
  
  
            else{
  
  System.out.println(csocket);
  
      ObjectInputStream inStream = new 
  
  ObjectInputStream(csocket.getInputStream());
  
  SI sysinfo= (SI) inStream.readObject();
  
  
  System.out.println("Received: "+sysinfo.otherInfo());
  
  System.out.println(ObjectStreamClass.lookup(sysinfo.getClass()).getSerialVersion
  UID());
  
  
     }
            }
  
  
        }
  
   catch (Exception e) {
  
  System.out.println("Exception"+ e.getMessage());
         }
  
              }
     };
  
  }
  </code></pre>
  
  <p>//class undergoing serialization     </p>
  
  <pre><code>public class SI implements Serializable
  
  { 
  
   private static final long serialVersionUID = 1L;     
  
  String otherInfo()
  
  {
  
   OperatingSystemMXBean bean = (com.sun.management.OperatingSystemMXBean) ManagementFactory
              .getOperatingSystemMXBean();
  
  
  
  String os_name=bean.getName();
  
  return os_name;  
  
  }
  
  }
  </code></pre>
  
  <p>//class A: It has main function and it executes first and user decides whether he/she want to be in server mode or in client mode. As user cannot be in 2 modes simultaneously..</p>
  
  <pre><code>class A
  
  {
  
  public static void main(String[] args) throws Exception
  
  {
  
      System.out.println("Enter 0 for Server 1 for Client Mode");
  
  Scanner s=new Scanner(System.in);
  
  int i=s.nextInt();
  
  if(i==0)
  
  {
  
      Server ser=new Server();
  
  ser.execute();
  
  }
  
  else if(i==1)
  
  {
  
      System.out.println("Enter IP");
  
  String conn=s.next();
  
  Client c=new Client(conn);
  
  }
  
  else
  
      System.out.println("Invalid Selection exit..");
  
  }
  
  }
  </code></pre>