aspose file tools *
The moose likes Beginning Java and the fly likes What comes out of the ObjectOutputStream is not what goes into the ObjectInputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What comes out of the ObjectOutputStream is not what goes into the ObjectInputStream" Watch "What comes out of the ObjectOutputStream is not what goes into the ObjectInputStream" New topic
Author

What comes out of the ObjectOutputStream is not what goes into the ObjectInputStream

Chad Schultz
Greenhorn

Joined: Mar 25, 2007
Posts: 23
Hey all... hope this is the right place to put this, I'm new to the forum. Only started using it this semester as I go through my Java class! I have an odd question...

I'm building a client/server Java application to give polls and suchlike. Someone can user the server to set the details in a complicated object (VatingSet). This object contains HashMaps of objects which themselves contain HashMaps... it's a little complicated. The server sends this object to the client. The client loads the data and lets the user vote/rate/sort the options. Then the client sends the object back to the server. The server creates a new object from what it received from the client, and then processes it, incrementing its main data object. So the net effect is that when the user selects a poll option and submits it, the program sends a score of 1. The server takes that and adds it to what it already has.

There's only one problem. After the first time the same client sends data, changes do not register. The user can select entirely different options and send an updated object into the ObjectOutputStream (I checked using the debugger- yes, the data is good when it is sent). However, when the server reads the object from the ObjectInputStream, it reads exactly the same data as it did the first time!

I noticed something interesting, however. If I use multiple clients,
then the server takes whatever they send first- no matter how they
change it- and assumes whatever they send after that is exactly the
same. So, to simplify:
Client A sends 4 --> Server receives 4
Client B sends 5 --> Server receives 5
Client A sends 2 --> Server receives 4 (the orginal value A sent)
Client B sends 1 --> Server receives 5
This continues, no matter how many times the client sends new data.

The files together make up over 70kb, so I shan't post them here. I uploaded the source code, however, to thazz.tripod.com/App.java and thazz.tripod.com/Server.java

Any ideas? I wonder if something is pass-by-reference, but I have no idea.

Thanks!
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Try writeUnshared() or reset(). HERE is some info about back-references. I'd say they are dangerously counter-intuitive.
[ April 27, 2007: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
Don't get me started about those stupid light bulbs.
 
subject: What comes out of the ObjectOutputStream is not what goes into the ObjectInputStream