Java Code Examples for com.jme3.network.serializing.Serializer#registerClass()

The following examples show how to use com.jme3.network.serializing.Serializer#registerClass() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClientSerializerRegistrationsService.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected void onInitialize( ClientServiceManager serviceManager ) {

    // Make sure our message type is registered if it isn't already
    if( Serializer.getExactSerializerRegistration(SerializerRegistrationsMessage.class) == null ) {
        // This is the minimum we'd need just to be able to register
        // the rest... otherwise we can't even receive this message.
        Serializer.registerClass(SerializerRegistrationsMessage.class);
        Serializer.registerClass(SerializerRegistrationsMessage.Registration.class);
    } else {
        log.log(Level.INFO, "Skipping registration of SerializerRegistrationsMessage.");
    }
    
    // Add our listener for that message type
    serviceManager.getClient().addMessageListener(this, SerializerRegistrationsMessage.class); 
}
 
Example 2
Source File: TestMessages.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void main(String[] args) throws IOException, InterruptedException{
    Serializer.registerClass(PingMessage.class);
    Serializer.registerClass(PongMessage.class);

    Server server = Network.createServer(5110);
    server.start();

    Client client = Network.connectToServer("localhost", 5110);
    client.start();

    server.addMessageListener(new ServerPingResponder(), PingMessage.class);
    client.addMessageListener(new ClientPingResponder(), PongMessage.class);

    System.out.println("Client: Sending ping message..");
    client.send(new PingMessage());
    
    Object obj = new Object();
    synchronized (obj){
        obj.wait();
    }
}
 
Example 3
Source File: TestThroughput.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void main(String[] args) throws IOException, InterruptedException {

        Serializer.registerClass(TestMessage.class);

        // Use this to test the client/server name version check
        //Server server = Network.createServer( "bad name", 42, 5110, 5110 );
        Server server = Network.createServer(5110, 5110);
        server.start();

        Client client = Network.connectToServer("localhost", 5110);
        client.start();

        client.addMessageListener(new TestThroughput(false), TestMessage.class);
        server.addMessageListener(new TestThroughput(true), TestMessage.class);

        Thread.sleep(1);

        TestMessage test = new TestMessage();
//        for( int i = 0; i < 10; i++ ) {
        while (true) {
//System.out.println( "sending." );
            client.send(test);
        }

        //Thread.sleep(5000);
    }
 
Example 4
Source File: TestMessages.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static void main(String[] args) throws IOException, InterruptedException{
    Serializer.registerClass(PingMessage.class);
    Serializer.registerClass(PongMessage.class);

    Server server = Network.createServer(5110);
    server.start();

    Client client = Network.connectToServer("localhost", 5110);
    client.start();

    server.addMessageListener(new ServerPingResponder(), PingMessage.class);
    client.addMessageListener(new ClientPingResponder(), PongMessage.class);

    System.out.println("Client: Sending ping message..");
    client.send(new PingMessage());
    
    Object obj = new Object();
    synchronized (obj){
        obj.wait();
    }
}
 
Example 5
Source File: TestThroughput.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static void main(String[] args) throws IOException, InterruptedException {

        Serializer.registerClass(TestMessage.class);

        // Use this to test the client/server name version check
        //Server server = Network.createServer( "bad name", 42, 5110, 5110 );
        Server server = Network.createServer(5110, 5110);
        server.start();

        Client client = Network.connectToServer("localhost", 5110);
        client.start();

        client.addMessageListener(new TestThroughput(false), TestMessage.class);
        server.addMessageListener(new TestThroughput(true), TestMessage.class);

        Thread.sleep(1);

        TestMessage test = new TestMessage();
//        for( int i = 0; i < 10; i++ ) {
        while (true) {
//System.out.println( "sending." );
            client.send(test);
        }

        //Thread.sleep(5000);
    }
 
Example 6
Source File: TestRemoteCall.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void main(String[] args) throws IOException, InterruptedException{
    Serializer.registerClass(Savable.class, new SavableSerializer());

    createServer();

    Client client = Network.connectToServer("localhost", 5110);
    client.start();

    ObjectStore store = new ObjectStore(client);
    ServerAccess access = store.getExposedObject("access", ServerAccess.class, true);
    boolean result = access.attachChild("Models/Oto/Oto.mesh.xml");
    System.out.println(result);
}
 
Example 7
Source File: TestSerialization.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void main(String[] args) throws IOException, InterruptedException{
    Serializer.registerClass(SomeObject.class);
    Serializer.registerClass(TestSerializationMessage.class);

    Server server = Network.createServer( 5110 );
    server.start();

    Client client = Network.connectToServer( "localhost", 5110 ); 
    client.start();

    server.addMessageListener(new TestSerialization(), TestSerializationMessage.class);
    client.send(new TestSerializationMessage(true));
    
    Thread.sleep(10000);
}
 
Example 8
Source File: ClientManager.java    From OpenRTS with MIT License 5 votes vote down vote up
public static void startClient() {
	Serializer.registerClass(Event.class);
	try {
		Thread.sleep(1000);
		client = Network.connectToServer("localhost", OpenRTSServer.PORT);
		client.addClientStateListener(new ClientStateListener());
		client.addMessageListener(new MessageListener(), Event.class);
	} catch (IOException | InterruptedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	client.start();
	
	EventManager.register(instance);
}
 
Example 9
Source File: OpenRTSServer.java    From OpenRTS with MIT License 5 votes vote down vote up
@Override
public void simpleInitApp() {
	try {
		myServer = Network.createServer(PORT, PORT);
		myServer.addMessageListener(new MessageListener(), Event.class);
		myServer.addConnectionListener(new ConnectionListener());
		myServer.start();
		logger.info("Server listening at :" + PORT);

	} catch (IOException e) {
		e.printStackTrace();
	}
	Serializer.registerClass(Event.class);
}
 
Example 10
Source File: TestRemoteCall.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void main(String[] args) throws IOException, InterruptedException{
    Serializer.registerClass(Savable.class, new SavableSerializer());

    createServer();

    Client client = Network.connectToServer("localhost", 5110);
    client.start();

    ObjectStore store = new ObjectStore(client);
    ServerAccess access = store.getExposedObject("access", ServerAccess.class, true);
    boolean result = access.attachChild("Models/Oto/Oto.mesh.xml");
    System.out.println(result);
}
 
Example 11
Source File: TestSerialization.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void main(String[] args) throws IOException, InterruptedException{
    Serializer.registerClass(SomeObject.class);
    Serializer.registerClass(TestSerializationMessage.class);

    Server server = Network.createServer( 5110 );
    server.start();

    Client client = Network.connectToServer( "localhost", 5110 ); 
    client.start();

    server.addMessageListener(new TestSerialization(), TestSerializationMessage.class);
    client.send(new TestSerializationMessage(true));
    
    Thread.sleep(10000);
}
 
Example 12
Source File: ServerSerializerRegistrationsService.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected void onInitialize( HostedServiceManager serviceManager ) {
    // Make sure our message type is registered
    Serializer.registerClass(SerializerRegistrationsMessage.class);
    Serializer.registerClass(SerializerRegistrationsMessage.Registration.class);
}
 
Example 13
Source File: TestChatServer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static void initializeClasses() {
    // Doing it here means that the client code only needs to
    // call our initialize. 
    Serializer.registerClass(ChatMessage.class);
}
 
Example 14
Source File: TestChatServer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static void initializeClasses() {
    // Doing it here means that the client code only needs to
    // call our initialize. 
    Serializer.registerClass(ChatMessage.class);
}