Link to home
Start Free TrialLog in
Avatar of orenm
orenm

asked on

ObjectOutputStream & Socket

Hi Expert,

We have an application that writes objects through a Socket.

The Application includes these lines of code:

_objectOutputStream = new ObjectOutputStream(_socket.getOutputStream());
_objectInputStream = new ObjectInputStream(_socket.getInputStream());

_objectOutputStream.writeObject(command);
Object inObject = _objectInputStream.readObject();

In general every thing works lovely and the objects (Command objects) "Ping-Pong" between the Client and the Server brings results for all the tasks.

But, there is a strange problem in one of the commands:

Problem preface:
----------------------------
One of the Command objects contains an object of class C1,
 which contains a collection of objects from class C2,
 which also contains objects of some other classes.
All the classes are "implements Serializable".
This object (of class C1) is fetched successfully (wrapped by a Command object).
This object is also written back to the server successfully (wrapped by another Command object).
This object is a member of a JDialog that lets the modifications of the object content.
Closing this JDialog solve the problem (which will be described on the next line) for the moment.

The Problem:
------------
Any subsequent writing of the object of class C1 (modified for several times) on the Client side,
     _objectOutputStream.writeObject(command);
wrapped by a Command object.
Results with:
Reading constantly (at the Server side) a Command object wrapping the same object that was written by the Client at the first time.
      _objectInputStream.readObject();

During all the object writing attempts at the Client:
     _objectOutputStream.writeObject(command);
The wrapping Command object (at the Client side) contains the current modified object ! ... ???


Thanks in advance,
Oren,
Israel.


Avatar of exorcist
exorcist

Hi,

I didnt quite understand your question, but it seems to me, that RMI might be a better alternative when transferring complex objects.
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of orenm

ASKER

Thanks,

(Short and to the point ...)

Oren.
oren,

I hate typing :-)
Thanks for the points.
Avatar of orenm

ASKER

Hi objects,

there is another question registered with my name:
 
File.delete()

See if you can help again (this time only 100 points ...).

Oren.