Messages not delivering. Error while selecting. java.lang.InstantiationException.

Hello, I’m trying to build a simple test about multiplayer and so far i managed to build the whole structure and a simple message system. Because I’m pretty new to JME I’m avoiding to create a custom serializer so I used the key features of my player class, instead of sending whole object, to create a simple message. The problem is: The message is getting sent, delivered but not read. I’m getting this error:

“GRAVE: [Server#1][???] Error while selecting. Message: java.lang.InstantiationException: mygame.PlayerMessage”



My message is:

[java]

package mygame;



import com.jme3.math.Quaternion;

import com.jme3.math.Vector3f;

import com.jme3.network.message.Message;

import com.jme3.network.serializing.Serializable;



@Serializable()

public class PlayerMessage extends Message{



public Vector3f pos;

public Quaternion rotation;

public String ID;



public PlayerMessage(Player p){

this.pos = p.pos;

this.rotation = p.rotation;

ID = p.ID;

}



}

[/java]



My listener(this is the server side listener, the only diference is that this one strafes messages to players):

[java]

package mygame;



import com.jme3.network.connection.Client;

import com.jme3.network.events.MessageListener;

import com.jme3.network.message.Message;

import java.io.IOException;

import java.util.ArrayList;



public class PlayerMessageListenerServer implements MessageListener {



ArrayList<Player> Players = new ArrayList<Player>();



public PlayerMessageListenerServer(){



}



private Player findByID(ArrayList<Player> Players, String ID){

for(Player p : Players){

if(p.ID.equals(ID)){

return p;

}

}

return null;

}



private void registerPlayer(Player p){

if(!Players.contains§)

Players.add§;

}



private void removePlayer(Player p){

if(Players.contains§)

Players.remove§;

}



private void strafePMessages(Client c){

for(Player p : Players){

try {

c.send(new PlayerMessage§);

} catch (IOException ex) {}

}

}



public void messageReceived(Message message) {

if(message instanceof PlayerMessage){

PlayerMessage pm = (PlayerMessage)message;

Player source = findByID(Players, pm.ID);

if(source != null){

source.pos = pm.pos;

source.rotation = pm.rotation;

System.out.println(“SERVER: received player > pos[”+source.pos.toString()+"]");

strafePMessages(pm.getClient());

}else{

registerPlayer(new Player(pm.ID));

System.out.println(“SERVER: registering player > ID[”+pm.ID+"]");

}

}

}



public void messageSent(Message message) {

throw new UnsupportedOperationException(“Not supported yet.”);

}



public void objectReceived(Object object) {

throw new UnsupportedOperationException(“Not supported yet.”);

}



public void objectSent(Object object) {

throw new UnsupportedOperationException(“Not supported yet.”);

}



}

[/java]



Also if someone knows where i can find more detailed information about SpiderMonkey (i read the wiki about 10 times), please tell me.

Thanks!

Ok, here goes…



First off:

@Serializable() needs a number uniquely identifying your message.



You also need to tell the serialzer about your message class. I’m assuming that you are already doing this on the client, but you also need to do this on the server. Any message class you register with the serializer needs to be registered on both ends.



Finally, and I’m not 100% sure about this, I think you need accessor methods for the variable in your message class. Also, I’m not sure the classes you have in your message (Vector3F, Quarternation) are serializable over spidermonkey. I don’t remember seeing a default serializer for those. If they are NOT serializable by default, you will either need to write a serializer for them, or you need to add them to your message in such a way that they are broken down into variables that are serializable by default.

You need a blank constructor.

h yes, that too… Forgot about that one.

Thanks! I’ll get into building a serializer. I’m being lazy now, my message framework is terrible,is simple though. Anyway I’ll take a deeper look into java networking API and build a better message system.