What comes out of the ObjectOutputStream is not what goes into the ObjectInputStream
Joined: Mar 25, 2007
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.