#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    ObjectOutputStream and new class()


    OK . I need an answer to this so i'll do it short and sweet.

    I'm using ObjectOutputStream to send objects from a server to my client.

    I made my own class (lets say X) that implements Serializable to be sent by my OOS.

    I have a timer that call a function that send this object 10 times;

    Inside the function I do X.anInt++; to increment the public int value inside the object.

    Just before sending I verify with a System.out.println(X.anInt) the value of this int which shows up to be correct

    After sending the client receive it with the wrong int value which remains at the initial 0;

    I noticed that the only way to get the right value on the client is to make a new X(); and assign to it the new good values every time before sending

    I just don't get it ... WHY! I'm testing the variable value before sending and it is CORRECT .... why do I have to make a NEW... why is the object showing good values before beeing sent and wrong ones once received and cast to its right class...

    I'm pretty sure that once I'll understand that i'll be a better person.

    Thanks in advance
  2. #2
  3. Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    May 2004
    Location
    Superior, CO, USA
    Posts
    2,418
    Rep Power
    1713
    Without some sort of SSCCE we'd just be taking a stab in the dark. Show some code.

IMN logo majestic logo threadwatch logo seochat tools logo