• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic