Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ObjectOutputStream & Socket

Posted on 2001-08-08
5
Medium Priority
?
294 Views
Last Modified: 2008-03-17
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.


0
Comment
Question by:orenm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:exorcist
ID: 6363889
Hi,

I didnt quite understand your question, but it seems to me, that RMI might be a better alternative when transferring complex objects.
0
 
LVL 92

Accepted Solution

by:
objects earned 800 total points
ID: 6366341
Call _objectOutputStream.reset() before writing the object.

ObjectOutputStream keeps track of objects written to it and when an object is sent the second time only the object handle is sent and not the actual object for efficiency reasons and to avoid circular references.

reset() tells it to forget what's already been sent.
0
 

Author Comment

by:orenm
ID: 6368041
Thanks,

(Short and to the point ...)

Oren.
0
 
LVL 92

Expert Comment

by:objects
ID: 6370375
oren,

I hate typing :-)
Thanks for the points.
0
 

Author Comment

by:orenm
ID: 6370402
Hi objects,

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

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

Oren.


0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

664 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question