use of com.github.dirtpowered.dirtmv.data.interfaces.Callback in project DirtMultiversion by DirtPowered.
the class Client method createClient.
public void createClient(UUID key, Callback callback) {
EventLoopGroup loopGroup = serverSession.getMain().getLoopGroup();
Bootstrap clientBootstrap = new Bootstrap();
clientBootstrap.group(loopGroup);
clientBootstrap.channel(NioSocketChannel.class);
clientBootstrap.option(ChannelOption.SO_KEEPALIVE, true);
clientBootstrap.option(ChannelOption.TCP_NODELAY, true);
Configuration c = serverSession.getMain().getConfiguration();
clientBootstrap.remoteAddress(new InetSocketAddress(c.getRemoteServerAddress(), c.getRemoteServerPort()));
clientBootstrap.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) {
ch.pipeline().addLast(ChannelConstants.DEFAULT_PIPELINE, new PipelineFactory(serverSession.getMain(), serverSession.getUserData(), PacketDirection.TO_CLIENT));
ch.pipeline().addLast(ChannelConstants.CLIENT_HANDLER, new ClientSession(serverSession.getMain(), key, serverSession, ch, callback));
}
});
clientBootstrap.connect().addListener((ChannelFutureListener) channelFuture -> {
if (!channelFuture.isSuccess()) {
serverSession.disconnect(ChatUtils.LEGACY_COLOR_CHAR + "cUnable to connect to remote server");
channelFuture.channel().close();
}
});
}
Aggregations