Java 类com.esotericsoftware.kryonet.FrameworkMessage.DiscoverHost 实例源码

项目:RuinsOfRevenge    文件:Client.java   
private void broadcast (int udpPort, DatagramSocket socket) throws IOException {
    ByteBuffer dataBuffer = ByteBuffer.allocate(64);
    serialization.write(null, dataBuffer, new DiscoverHost());
    dataBuffer.flip();
    byte[] data = new byte[dataBuffer.limit()];
    dataBuffer.get(data);
    for (NetworkInterface iface : Collections.list(NetworkInterface.getNetworkInterfaces())) {
        for (InetAddress address : Collections.list(iface.getInetAddresses())) {
            // Java 1.5 doesn't support getting the subnet mask, so try the two most common.
            byte[] ip = address.getAddress();
            ip[3] = -1; // 255.255.255.0
            socket.send(new DatagramPacket(data, data.length, InetAddress.getByAddress(ip), udpPort));
            ip[2] = -1; // 255.255.0.0
            socket.send(new DatagramPacket(data, data.length, InetAddress.getByAddress(ip), udpPort));
        }
    }
    if (DEBUG) debug("kryonet", "Broadcasted host discovery on port: " + udpPort);
}
项目:Mindustry    文件:KryoClient.java   
@Override
public void pingHost(String address, int port, Consumer<Host> valid, Consumer<IOException> invalid){
    Thread thread = new Thread(() -> {
        try {

            Serialization ser = (Serialization) UCore.getPrivate(client, "serialization");
            DatagramSocket socket = new DatagramSocket();
            ByteBuffer dataBuffer = ByteBuffer.allocate(64);
            ser.write(dataBuffer, new DiscoverHost());

            dataBuffer.flip();
            byte[] data = new byte[dataBuffer.limit()];
            dataBuffer.get(data);
            socket.send(new DatagramPacket(data, data.length, InetAddress.getByName(address), port));

            socket.setSoTimeout(2000);

            addresses.clear();

            DatagramPacket packet = handler.onRequestNewDatagramPacket();

            socket.receive(packet);

            handler.onDiscoveredHost(packet);

            Host host = addresses.values().next();

            if (host != null) {
                Gdx.app.postRunnable(() -> valid.accept(host));
            } else {
                Gdx.app.postRunnable(() -> invalid.accept(new IOException("Outdated server.")));
            }
        } catch (IOException e) {
            Gdx.app.postRunnable(() -> invalid.accept(e));
        }
    });

    thread.setDaemon(true);
    thread.start();
}
项目:EsperDist    文件:KryoSerialization.java   
public KryoSerialization (Kryo kryo) {
    this.kryo = kryo;

    kryo.register(RegisterTCP.class);
    kryo.register(RegisterUDP.class);
    kryo.register(KeepAlive.class);
    kryo.register(DiscoverHost.class);
    kryo.register(Ping.class);

    input = new Input(byteBufferInputStream, 512);
    output = new Output(byteBufferOutputStream, 512);
}
项目:EsperDist    文件:JsonSerialization.java   
public JsonSerialization () {
    json.addClassTag("RegisterTCP", RegisterTCP.class);
    json.addClassTag("RegisterUDP", RegisterUDP.class);
    json.addClassTag("KeepAlive", KeepAlive.class);
    json.addClassTag("DiscoverHost", DiscoverHost.class);
    json.addClassTag("Ping", Ping.class);

    json.setWriter(writer);
}
项目:EsperDist    文件:KryoSerialization.java   
public KryoSerialization (Kryo kryo) {
    this.kryo = kryo;

    kryo.register(RegisterTCP.class);
    kryo.register(RegisterUDP.class);
    kryo.register(KeepAlive.class);
    kryo.register(DiscoverHost.class);
    kryo.register(Ping.class);

    input = new Input(byteBufferInputStream, 512);
    output = new Output(byteBufferOutputStream, 512);
}
项目:EsperDist    文件:JsonSerialization.java   
public JsonSerialization () {
    json.addClassTag("RegisterTCP", RegisterTCP.class);
    json.addClassTag("RegisterUDP", RegisterUDP.class);
    json.addClassTag("KeepAlive", KeepAlive.class);
    json.addClassTag("DiscoverHost", DiscoverHost.class);
    json.addClassTag("Ping", Ping.class);

    json.setWriter(writer);
}
项目:magic-realm    文件:KryoSerialization.java   
public KryoSerialization (Kryo kryo) {
    this.kryo = kryo;

    kryo.register(RegisterTCP.class);
    kryo.register(RegisterUDP.class);
    kryo.register(KeepAlive.class);
    kryo.register(DiscoverHost.class);
    kryo.register(Ping.class);

    input = new ByteBufferInput();
    output = new ByteBufferOutput();
}
项目:magic-realm    文件:JsonSerialization.java   
public JsonSerialization () {
    json.addClassTag("RegisterTCP", RegisterTCP.class);
    json.addClassTag("RegisterUDP", RegisterUDP.class);
    json.addClassTag("KeepAlive", KeepAlive.class);
    json.addClassTag("DiscoverHost", DiscoverHost.class);
    json.addClassTag("Ping", Ping.class);

    json.setWriter(writer);
}
项目:flume2storm    文件:MyKryoSerialization.java   
public MyKryoSerialization(Kryo kryo, int objectSize) {
  this.kryo = kryo;

  kryo.register(RegisterTCP.class);
  kryo.register(RegisterUDP.class);
  kryo.register(KeepAlive.class);
  kryo.register(DiscoverHost.class);
  kryo.register(Ping.class);

  input = new Input(byteBufferInputStream, objectSize);
  output = new Output(byteBufferOutputStream, objectSize);
}
项目:kingdom    文件:KryoSerialization.java   
public KryoSerialization (Kryo kryo) {
    this.kryo = kryo;

    kryo.register(RegisterTCP.class);
    kryo.register(RegisterUDP.class);
    kryo.register(KeepAlive.class);
    kryo.register(DiscoverHost.class);
    kryo.register(Ping.class);

    input = new Input(byteBufferInputStream, 512);
    output = new Output(byteBufferOutputStream, 512);
}
项目:kingdom    文件:JsonSerialization.java   
public JsonSerialization () {
    json.addClassTag("RegisterTCP", RegisterTCP.class);
    json.addClassTag("RegisterUDP", RegisterUDP.class);
    json.addClassTag("KeepAlive", KeepAlive.class);
    json.addClassTag("DiscoverHost", DiscoverHost.class);
    json.addClassTag("Ping", Ping.class);

    json.setWriter(writer);
}
项目:the-erder    文件:KryoSerialization.java   
public KryoSerialization(Kryo kryo) {
    this.kryo = kryo;

    kryo.register(RegisterTCP.class);
    kryo.register(RegisterUDP.class);
    kryo.register(KeepAlive.class);
    kryo.register(DiscoverHost.class);
    kryo.register(Ping.class);

    input = new ByteBufferInput();
    output = new ByteBufferOutput();
}
项目:the-erder    文件:JsonSerialization.java   
public JsonSerialization() {
    json.addClassTag("RegisterTCP", RegisterTCP.class);
    json.addClassTag("RegisterUDP", RegisterUDP.class);
    json.addClassTag("KeepAlive", KeepAlive.class);
    json.addClassTag("DiscoverHost", DiscoverHost.class);
    json.addClassTag("Ping", Ping.class);

    json.setWriter(writer);
}
项目:kryonet    文件:KryoSerialization.java   
public KryoSerialization (Kryo kryo) {
    this.kryo = kryo;

    kryo.register(RegisterTCP.class);
    kryo.register(RegisterUDP.class);
    kryo.register(KeepAlive.class);
    kryo.register(DiscoverHost.class);
    kryo.register(Ping.class);

    input = new ByteBufferInput();
    output = new ByteBufferOutput();
}
项目:kryonet    文件:JsonSerialization.java   
public JsonSerialization () {
    json.addClassTag("RegisterTCP", RegisterTCP.class);
    json.addClassTag("RegisterUDP", RegisterUDP.class);
    json.addClassTag("KeepAlive", KeepAlive.class);
    json.addClassTag("DiscoverHost", DiscoverHost.class);
    json.addClassTag("Ping", Ping.class);

    json.setWriter(writer);
}
项目:RuinsOfRevenge    文件:KryoSerialization.java   
public KryoSerialization (Kryo kryo) {
    this.kryo = kryo;

    kryo.register(RegisterTCP.class);
    kryo.register(RegisterUDP.class);
    kryo.register(KeepAlive.class);
    kryo.register(DiscoverHost.class);
    kryo.register(Ping.class);

    input = new Input(byteBufferInputStream, 512);
    output = new Output(byteBufferOutputStream, 512);
}
项目:RuinsOfRevenge    文件:JsonSerialization.java   
public JsonSerialization () {
    json.addClassTag("RegisterTCP", RegisterTCP.class);
    json.addClassTag("RegisterUDP", RegisterUDP.class);
    json.addClassTag("KeepAlive", KeepAlive.class);
    json.addClassTag("DiscoverHost", DiscoverHost.class);
    json.addClassTag("Ping", Ping.class);
}