This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I'm currently trying to get a network application running. 2 instances from the same machine, one acting as Server, the other as Client. The Client continuously sends HashMaps of <String,Integer> type which have constantly changing values to the Server. It does this by an 'ObjectOutputStream(Socket.getOutputStream())', where it writes the object with writeObject(HashMap);, then flush() it. So far so good, right??
On the server end, it loops over and over collecting objects from an ObjectInputStream using readObject().
The problem is, it never, ever receives any updated HashMaps. It gets the first HashMap sent, and that's it. I can confirm this with System.out.println(readObject()); I cannot for the life of my understand why this is the case. Does anyone else?
An ObjectOutputStream keeps track of which objects it has already sent, and doesn't send them more than once. Actually it's somewhat more complicated than that, but that's the general idea. If you want to send an object over again, after its state has changed, then there's a reset() method in ObjectOutputStream which you should call.