I am writing an application (a multiplayer game) where objects need to be passed from one instance of the application to another (and very quickly) via a server.
I am using ObjectOutputStreams
and ObjectInputStreams
obtained through the sockets to do this.
However, the state of the objects being passed is constantly being updated, meaning the typical writeObject()
method won't do the trick (it only writes the object once, then passes a reference to it subsequent times it is called, meaning the values of its instance variables are never actually updated).
To "fix" this I have been calling the ObjectOutputStream.reset()
method after every call to writeObject()
, which does solve the problem of updating the object state; however, it runs much too slow, which I assume is a result of the objects being passed in their entirety each "refresh".
My question then is, how do I update the state of the object I am passing over the network without having to entirely rewrite the object? (I'm assuming this is how I would speed things up; if I'm wrong, or if other methods exist, please share) Thank you in advance for any advice!
Also, regarding the size of the object being passed: it isn't overly large... A couple of boolean variables, a couple of double arrays, and some other minor variables (No lists of length 1000 each containing another list).