Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Chad Schultz
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic