Everytime I try to send a message to the server, I’ve got a runtimeexception saying ‘error serializing message’.How can i solve this?
You need to show us the actual exception… with root cause and everything. Otherwise, there are about half a dozen different things I could randomly guess it might be.
INFO: Connection established, id:2.
17-jul-2011 23:20:23 com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.RuntimeException: Error serializing message
Caused by: java.io.IOException: The class messages.JoiningMessage is not registered in the serializer!
… 8 more
BUILD SUCCESSFUL (total time: 41 seconds)
That is because “The class messages.JoiningMessage is not registered in the serializer.”
So you have not registered your message class with Serializer. It doesn’t know how to serialize it.
Isn’t that done by writing ‘@Serializable’ at the beginning of your class(which I have done)? Or do i have to call a method to register them?
You have to call a method on Serializer to register them…
and… all classes must be registered in the exact same order on both client and server. So the recommended advice is to do this in a static method shared by client and server so as not to easily forget something.
Note: I believe that if you specify your own ID in @Serializable that it auto registers them on write… but you’d still have the problem of not knowing what class to instantiate at the other end of the connection. Registering a serializable class has the effect of giving it a “unique ID” that the server and client can use to resolve to the actual class. If the class hasn’t been registered then the side reading one of these IDs won’t know which class to instantiate.
It makes for very fast/tight network data but is kind of fragile if care is not taken to register the classes as outlined above. Someday I plan to rewrite it but so far it’s only a few moments of pain every now and then… and there are always bigger things to deal with it seems.
thanks, I got it to work.