use of com.esotericsoftware.kryonet.ServerDiscoveryHandler in project ProjektGG by eskalon.
the class BaseGameServer method startBroadcastServer.
private void startBroadcastServer() {
broadcastServer = new Server();
broadcastServer.start();
broadcastServer.getKryo().register(DiscoveryResponsePacket.class);
broadcastServer.setDiscoveryHandler(new ServerDiscoveryHandler() {
@Override
public boolean onDiscoverHost(DatagramChannel datagramChannel, InetSocketAddress fromAddress) throws IOException {
DiscoveryResponsePacket packet = new DiscoveryResponsePacket(serverSetup.getPort(), serverSetup.getGameName(), players.size(), serverSetup.getMaxPlayerCount());
ByteBuffer buffer = ByteBuffer.allocate(256);
broadcastServer.getSerialization().write(null, buffer, packet);
buffer.flip();
datagramChannel.send(buffer, fromAddress);
return true;
}
});
try {
broadcastServer.bind(0, UDP_DISCOVER_PORT);
Log.info("Server", "Broadcast server started");
} catch (IOException e1) {
Log.error("Server", "Broadcast server couldn't be started: %s", e1);
}
}
Aggregations