Package com.esotericsoftware.kryonet

Examples of com.esotericsoftware.kryonet.Client


      }
    });

    // ----

    Client client = new Client();
    register(client.getKryo());

    ObjectSpace clientObjectSpace = new ObjectSpace(client);
    final TestObjectImpl clientTestObject = new TestObjectImpl(1234);
    clientObjectSpace.register(12, clientTestObject);

    startEndPoint(client);
    client.addListener(new Listener() {
      public void connected (final Connection connection) {
        runTest(connection, 42, 4321);
      }

      public void received (Connection connection, Object object) {
        if (!(object instanceof MessageWithTestObject)) return;
        MessageWithTestObject m = (MessageWithTestObject)object;
        System.out.println(clientTestObject.value);
        System.out.println(((TestObjectImpl)m.testObject).value);
        assertEquals(1234f, m.testObject.other());
        stopEndPoints(2000);
      }
    });
    client.connect(5000, host, tcpPort, udpPort);

    waitForThreads();
  }
View Full Code Here


      }
    });

    // ----

    Client client = new Client();
    register(client.getKryo());

    startEndPoint(client);
    client.addListener(new Listener() {
      public void connected (final Connection connection) {
        new Thread() {
          public void run () {
            TestObject test = ObjectSpace.getRemoteObject(connection, 42, TestObject.class);
            test.other();
            // Timeout on purpose.
            try {
              ((RemoteObject)test).setResponseTimeout(200);
              test.slow();
              fail();
            } catch (TimeoutException ignored) {
            }
            try {
              Thread.sleep(300);
            } catch (InterruptedException ex) {
            }
            ((RemoteObject)test).setResponseTimeout(3000);
            for (int i = 0; i < 256; i++)
              assertEquals(4321f, (float)test.other());
            for (int i = 0; i < 256; i++)
              test.moo();
            for (int i = 0; i < 256; i++)
              test.moo("" + i);
            for (int i = 0; i < 256; i++)
              test.moo("" + i, 0);
            connection.sendTCP(new MessageWithTestObject());
          }
        }.start();
      }
    });
    client.connect(5000, host, tcpPort);

    waitForThreads();
  }
View Full Code Here

      }
    });

    // ----

    Client client = new Client();
    register(client.getKryo());
    startEndPoint(client);

    // The ThreadedListener means the network thread won't be blocked when waiting for RMI responses.
    client.addListener(new ThreadedListener(new Listener() {
      public void connected (final Connection connection) {
        TestObject test = ObjectSpace.getRemoteObject(connection, 42, TestObject.class);
        // Normal remote method call.
        assertEquals(43.21f, test.other());
        // Make a remote method call that returns another remote proxy object.
        OtherObject otherObject = test.getOtherObject();
        // Normal remote method call on the second object.
        assertEquals(12.34f, otherObject.value());
        // When a remote proxy object is sent, the other side recieves its actual remote object.
        connection.sendTCP(otherObject);
      }
    }));
    client.connect(5000, host, tcpPort);

    waitForThreads();
  }
View Full Code Here

    public static void main(String[] args) throws IOException {
        final Server server = new Server();
        server.start();
        server.bind(12_345);

        final Client client = new Client();
        client.start();
        client.connect(5_000, "localhost", 12_345);

        client.addListener(new Listener() {
            @Override
            public void received(Connection connection, Object object) {
                LOG.log(Level.INFO, "Received message {0} in thread {1}", new Object[]{object.toString(), Thread.currentThread().toString()});
                try {
                    Thread.sleep(100);
                } catch (InterruptedException ex) {
                    LOG.log(Level.SEVERE, null, ex);
                }
            }
        });

        final String text = "test";

        final Timer timer = new Timer("timer 1");
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                server.sendToAllTCP(text);
            }
        }, 0, 100);

        final Timer timer2 = new Timer("timer 2");
        timer2.schedule(new TimerTask() {
            @Override
            public void run() {
                LOG.log(Level.INFO, "cancel everything");
                timer.cancel();
                client.stop();
                server.stop();
                timer2.cancel();
            }
        }, 2_000);
    }
View Full Code Here

        kryo.register(Packet.class);
       
        server.start();
        server.bind(12_345);
       
        final Client client = new Client();
        kryo = client.getKryo();
        kryo.register(Packet.class);       
       
        client.start();
        client.connect(5_000, "localhost", 12_345);       
       
        client.addListener(new Listener() {
            @Override
            public void received(Connection connection, Object object) {
                System.out.println("type of object " + object.getClass().getName());
                if (object instanceof Packet) {
                    System.out.println("type of content " + ((Packet) object).getContent().getClass().getName());
                }
            }
        });       
       
        server.sendToAllTCP(new Packet<String>("Hello world!"));
       

        // stopping timer after 2s
        final Timer timer = new Timer("timer");
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                timer.cancel();
                client.stop();
                server.stop();
            }
        }, 200_000);       
       
    }
View Full Code Here

        server.bind(12_345);
        LogListener listener = new LogListener();
        server.addListener(listener);

        // start and connect client
        final Client client = new Client();
        client.start();
        client.connect(1_000, "localhost", 12_345);

        // send some messages
        client.sendTCP("hallo");
        client.sendTCP("bye");

        // force disconnect
        listener.disconnect(client);


        // set timer and stop after 5s
        final Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                timer.cancel();
                client.stop();
                server.stop();
            }
        }, 5_000);
    }
View Full Code Here

        LOG.log(Level.INFO, "[CLIENT] Client connection initiated.");
        if (kryoClient != null) {
            return false;
        }

        kryoClient = new Client();

        KryoRegistration.register(kryoClient.getKryo());

        kryoClient.start();
        kryoClient.addListener(this);
View Full Code Here

public class RemoteMinecraft implements IMinecraftInterface {
  Client client;
  static NetGetBiomeDataResult currentResults = null;
 
  public RemoteMinecraft(String address) {
    client = new Client(65536, 65536);
    Kryo kryo = client.getKryo();
    kryo.register(NetCreateWorldRequest.class);
    kryo.register(NetGetBiomeDataRequest.class);
    kryo.register(NetGetBiomeDataResult.class);
    kryo.register(NetBiome.class);
View Full Code Here

TOP

Related Classes of com.esotericsoftware.kryonet.Client

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.