com.jme3.network.Server Java Examples

The following examples show how to use com.jme3.network.Server. 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: RpcHostedService.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 *  Used internally to setup the message delegator that will
 *  handle HostedConnection specific messages and forward them
 *  to that connection's RpcConnection.
 */
@Override
protected void onInitialize( HostedServiceManager serviceManager ) {
    Server server = serviceManager.getServer();
     
    // A general listener for forwarding the messages
    // to the client-specific handler
    this.delegator = new SessionDataDelegator(RpcConnection.class, 
                                              ATTRIBUTE_NAME,
                                              true);
    server.addMessageListener(delegator, delegator.getMessageTypes());

    if( log.isLoggable(Level.FINEST) ) {
        log.log(Level.FINEST, "Registered delegator for message types:{0}", Arrays.asList(delegator.getMessageTypes()));
    }
}
 
Example #2
Source File: TestRemoteCall.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static void createServer(){
    serverApp = new SimpleApplication() {
        @Override
        public void simpleInitApp() {
        }
    };
    serverApp.start();

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

        ObjectStore store = new ObjectStore(server);
        store.exposeObject("access", new ServerAccessImpl());
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}
 
Example #3
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 #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: TestNetworkStress.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static void main(String[] args) throws IOException, InterruptedException{
    Logger.getLogger("").getHandlers()[0].setLevel(Level.OFF);
    
    Server server = Network.createServer(5110);
    server.start();
    server.addConnectionListener(new TestNetworkStress());

    for (int i = 0; i < 1000; i++){
        Client client = Network.connectToServer("localhost", 5110);
        client.start();

        Thread.sleep(10);
        
        client.close();
    }
}
 
Example #6
Source File: TestRemoteCall.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void createServer(){
    serverApp = new SimpleApplication() {
        @Override
        public void simpleInitApp() {
        }
    };
    serverApp.start();

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

        ObjectStore store = new ObjectStore(server);
        store.exposeObject("access", new ServerAccessImpl());
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}
 
Example #7
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 #8
Source File: TestChatServer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void main(String... args) throws Exception {
    initializeClasses();

    // Use this to test the client/server name version check
    Server server = Network.createServer(NAME, VERSION, PORT, UDP_PORT);
    server.start();

    ChatHandler handler = new ChatHandler();
    server.addMessageListener(handler, ChatMessage.class);

    // Keep running basically forever
    synchronized (NAME) {
        NAME.wait();
    }
}
 
Example #9
Source File: ObjectStore.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ObjectStore(Server server) {
    this.server = server;
    server.addMessageListener(serverEventHandler, 
            RemoteObjectDefMessage.class,
            RemoteMethodCallMessage.class,
            RemoteMethodReturnMessage.class);
    server.addConnectionListener(serverEventHandler);
}
 
Example #10
Source File: AbstractHostedConnectionService.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 *  Called internally when a new connection is detected for
 *  the server.  If the current autoHost property is true then
 *  startHostingOnConnection(hc) is called. 
 */
@Override
public void connectionAdded(Server server, HostedConnection hc) {
    if( log.isLoggable(Level.FINEST) ) {
        log.log(Level.FINEST, "connectionAdded({0}, {1})", new Object[]{server, hc});
    }    
    if( autoHost ) {
        startHostingOnConnection(hc);
    }
}
 
Example #11
Source File: AbstractHostedConnectionService.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 *  Called internally when an existing connection is leaving
 *  the server.  This method always calls stopHostingOnConnection(hc).
 *  Implementations should be aware that if they stopHostingOnConnection()
 *  early that they will get a second call when the connection goes away.
 */
@Override
public void connectionRemoved(Server server, HostedConnection hc) {
    if( log.isLoggable(Level.FINEST) ) {
        log.log(Level.FINEST, "connectionRemoved({0}, {1})", new Object[]{server, hc});
    }    
    stopHostingOnConnection(hc);
}
 
Example #12
Source File: RmiHostedService.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 *  Called internally when an existing connection is leaving
 *  the server.  If the current autoHost property is true then
 *  stopHostingOnConnection(hc) is called. 
 */
@Override
public void connectionRemoved(Server server, HostedConnection hc) {
    if( log.isLoggable(Level.FINEST) ) {
        log.log(Level.FINEST, "connectionRemoved({0}, {1})", new Object[]{server, hc});
    }
    if( autoHost ) {    
        stopHostingOnConnection(hc);
    }
}
 
Example #13
Source File: RmiHostedService.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 *  Called internally when a new connection is detected for
 *  the server.  If the current autoHost property is true then
 *  startHostingOnConnection(hc) is called. 
 */
@Override
public void connectionAdded(Server server, HostedConnection hc) {
    if( log.isLoggable(Level.FINEST) ) {
        log.log(Level.FINEST, "connectionAdded({0}, {1})", new Object[]{server, hc});
    }    
    if( autoHost ) {
        startHostingOnConnection(hc);
    }
}
 
Example #14
Source File: ServerSerializerRegistrationsService.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void connectionAdded(Server server, HostedConnection hc) {
    // Just in case
    super.connectionAdded(server, hc);
 
    // Send the client the registration information
    hc.send(SerializerRegistrationsMessage.INSTANCE);
}
 
Example #15
Source File: ObjectStore.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void connectionRemoved(Server server, HostedConnection conn) {
}
 
Example #16
Source File: RpcHostedService.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 *  Used internally to remove the message delegator from the
 *  server.
 */
@Override
public void terminate(HostedServiceManager serviceManager) {
    Server server = serviceManager.getServer();
    server.removeMessageListener(delegator, delegator.getMessageTypes());
}
 
Example #17
Source File: AbstractHostedService.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 *  Returns the server for this hosted service or null if
 *  the service is not yet attached.
 */   
protected Server getServer() {
    HostedServiceManager hsm = getServiceManager();
    return hsm == null ? null : hsm.getServer();
}
 
Example #18
Source File: TestNetworkStress.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void connectionRemoved(Server server, HostedConnection conn) {
}
 
Example #19
Source File: TestNetworkStress.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void connectionAdded(Server server, HostedConnection conn) {
    System.out.println("Client Connected: "+conn.getId());
    //conn.close("goodbye");
}
 
Example #20
Source File: ObjectStore.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void connectionAdded(Server server, HostedConnection conn) {
    onConnection(conn);
}
 
Example #21
Source File: ConnectionListener.java    From OpenRTS with MIT License 4 votes vote down vote up
@Override
public void connectionRemoved(Server server, HostedConnection conn) {
	logger.info(server.getGameName() + " lost a connection:" + conn.getId());

}
 
Example #22
Source File: ConnectionListener.java    From OpenRTS with MIT License 4 votes vote down vote up
@Override
public void connectionAdded(Server server, HostedConnection conn) {
	logger.info(server.getGameName() + " has a new connection:" + conn.getId());

}
 
Example #23
Source File: HostedServiceManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void connectionRemoved(Server server, HostedConnection hc) {
    removeConnection(hc);
}
 
Example #24
Source File: HostedServiceManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void connectionAdded(Server server, HostedConnection hc) {
    addConnection(hc);
}
 
Example #25
Source File: HostedServiceManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 *  Returns the network Server associated with this HostedServiceManager.
 */
public Server getServer() {
    return server;
}
 
Example #26
Source File: HostedServiceManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 *  Creates a HostedServiceManager for the specified network Server.
 */    
public HostedServiceManager( Server server ) {
    this.server = server;
    this.connectionObserver = new ConnectionObserver();
    server.addConnectionListener(connectionObserver);
}
 
Example #27
Source File: AbstractHostedService.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 *  Default implementation does nothing.  Implementations can
 *  override this to peform custom leaving connection behavior.
 */
@Override
public void connectionRemoved(Server server, HostedConnection hc) {
}
 
Example #28
Source File: AbstractHostedService.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 *  Default implementation does nothing.  Implementations can
 *  override this to peform custom new connection behavior.
 */
@Override
public void connectionAdded(Server server, HostedConnection hc) {
}