Package com.esotericsoftware.kryonet

Source Code of com.esotericsoftware.kryonet.PingTest

package com.esotericsoftware.kryonet;

import java.io.IOException;
import java.util.Timer;

import com.esotericsoftware.kryonet.FrameworkMessage.Ping;

public class PingTest extends KryoNetTestCase {
  public void testPing () throws IOException {
    final Server server = new Server();
    startEndPoint(server);
    server.bind(tcpPort);

    // ----

    final Client client = new Client();
    startEndPoint(client);
    client.addListener(new Listener() {
      public void connected (Connection connection) {
        client.updateReturnTripTime();
      }

      public void received (Connection connection, Object object) {
        if (object instanceof Ping) {
          Ping ping = (Ping)object;
          if (ping.isReply) System.out.println("Ping: " + connection.getReturnTripTime());
          client.updateReturnTripTime();
        }
      }
    });
    client.connect(5000, host, tcpPort);

    waitForThreads(5000);
  }
}
TOP

Related Classes of com.esotericsoftware.kryonet.PingTest

TOP
Copyright © 2018 www.massapi.com. 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.