com.jme3.network.Client Java Examples

The following examples show how to use com.jme3.network.Client. 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: 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 #2
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 #3
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 #4
Source File: TestChatClient.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void messageReceived(Client source, Message m) {
    ChatMessage chat = (ChatMessage) m;

    System.out.println("Received:" + chat);

    // One of the least efficient ways to add text to a
    // JEditorPane
    chatMessages.append("<font color='#00a000'>" + (m.isReliable() ? "TCP" : "UDP") + "</font>");
    chatMessages.append(" -- <font color='#000080'><b>" + chat.getName() + "</b></font> : ");
    chatMessages.append(chat.getMessage());
    chatMessages.append("<br />");
    String s = "<html><body>" + chatMessages + "</body></html>";
    chatLog.setText(s);

    // Set selection to the end so that the scroll panel will scroll
    // down.
    chatLog.select(s.length(), s.length());
}
 
Example #5
Source File: TestChatClient.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void messageReceived(Client source, Message m) {
    ChatMessage chat = (ChatMessage) m;

    System.out.println("Received:" + chat);

    // One of the least efficient ways to add text to a
    // JEditorPane
    chatMessages.append("<font color='#00a000'>" + (m.isReliable() ? "TCP" : "UDP") + "</font>");
    chatMessages.append(" -- <font color='#000080'><b>" + chat.getName() + "</b></font> : ");
    chatMessages.append(chat.getMessage());
    chatMessages.append("<br />");
    String s = "<html><body>" + chatMessages + "</body></html>";
    chatLog.setText(s);

    // Set selection to the end so that the scroll panel will scroll
    // down.
    chatLog.select(s.length(), s.length());
}
 
Example #6
Source File: RpcClientService.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 *  Used internally to setup the RpcConnection and MessageDelegator.
 */
@Override
@SuppressWarnings("unchecked")
protected void onInitialize( ClientServiceManager serviceManager ) {        
    Client client = serviceManager.getClient();
    this.rpc = new RpcConnection(client);
    
    delegator = new ObjectMessageDelegator(rpc, true);       
    client.addMessageListener(delegator, delegator.getMessageTypes());                   
}
 
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: 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 #9
Source File: ObjectStore.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ObjectStore(Client client) {
    this.client = client;
    client.addMessageListener(clientEventHandler, 
            RemoteObjectDefMessage.class,
            RemoteMethodCallMessage.class,
            RemoteMethodReturnMessage.class);
    client.addClientStateListener(clientEventHandler);
}
 
Example #10
Source File: MessageListener.java    From OpenRTS with MIT License 5 votes vote down vote up
@Override
public void messageReceived(Client source, Message message) {
	if (message instanceof InputEvent) {
		// do something with the message
		InputEvent helloMessage = (InputEvent) message;
		System.out.println("Client #" + source.getId() + " received: '" + helloMessage.getActionCommand() + "'");
		EventManager.post(helloMessage);
	} // else...
}
 
Example #11
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 #12
Source File: TestChatClient.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void handleError( Client source, Throwable t ) {
    System.out.println("handleError(" + source + ", " + t + ")");
    JOptionPane.showMessageDialog(rootPane, 
                                  String.valueOf(t), 
                                  "Connection Error", 
                                  JOptionPane.ERROR_MESSAGE);
}
 
Example #13
Source File: TestChatClient.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void clientDisconnected(Client c, DisconnectInfo info) {
    System.out.println("clientDisconnected(" + c + "):" + info);
    if( info != null ) {
        // The connection was closed by the server
        JOptionPane.showMessageDialog(rootPane, 
                                  info.reason, 
                                  "Connection Closed", 
                                  JOptionPane.INFORMATION_MESSAGE);
        dispose();
    }
}
 
Example #14
Source File: RpcClientService.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 *  Used internally to unregister the RPC MessageDelegator that
 *  was previously added to the network Client.
 */
@Override
@SuppressWarnings("unchecked")
public void terminate( ClientServiceManager serviceManager ) {
    Client client = serviceManager.getClient();
    client.removeMessageListener(delegator, delegator.getMessageTypes());                   
}
 
Example #15
Source File: ClientStateListener.java    From OpenRTS with MIT License 4 votes vote down vote up
@Override
public void clientConnected(Client c) {
	logger.info("connection to Server successfully. There is a game name:" + c.getGameName());

}
 
Example #16
Source File: ClientStateListener.java    From OpenRTS with MIT License 4 votes vote down vote up
@Override
public void clientDisconnected(Client c, DisconnectInfo info) {
	logger.warning("lost connection" + c.getGameName() + " because of " + info.reason);
}
 
Example #17
Source File: ObjectStore.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void clientConnected(Client c) {
    onConnection(null);
}
 
Example #18
Source File: ObjectStore.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void clientDisconnected(Client c, DisconnectInfo info) {
}
 
Example #19
Source File: TestChatClient.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void clientConnected(Client c) {
    System.out.println("clientConnected(" + c + ")");
}
 
Example #20
Source File: ClientSerializerRegistrationsService.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void messageReceived( Client source, Message m ) {
    // We only wait for one kind of message...
    SerializerRegistrationsMessage msg = (SerializerRegistrationsMessage)m;
    msg.registerAll();
}
 
Example #21
Source File: TestMessages.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void messageReceived(Client source, com.jme3.network.Message message) {
    if (message instanceof PongMessage){
        System.out.println("Client: Received pong message!");
    }
}
 
Example #22
Source File: ClientServiceManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 *  Returns the network Client associated with this ClientServiceManager.
 */   
public Client getClient() {
    return client;
}
 
Example #23
Source File: ClientServiceManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 *  Creates a new ClientServiceManager for the specified network Client.
 */   
public ClientServiceManager( Client client ) {
    this.client = client;
}
 
Example #24
Source File: AbstractClientService.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 *  Returns the client for this client service or null if
 *  the service is not yet attached.
 */   
protected Client getClient() {
    ClientServiceManager csm = getServiceManager();
    return csm == null ? null : csm.getClient();
}