use of org.terasology.engine.network.internal.ServerInfoRequestHandler in project Terasology by MovingBlocks.
the class InfoRequestPipelineFactory method initChannel.
@Override
protected void initChannel(Channel ch) throws Exception {
JoinStatusImpl joinStatus = new JoinStatusImpl();
ChannelPipeline p = ch.pipeline();
p.addLast(MetricRecordingHandler.NAME, new MetricRecordingHandler());
p.addLast("inflateDecoder", new Lz4FrameDecoder());
p.addLast("lengthFrameDecoder", new LengthFieldBasedFrameDecoder(8388608, 0, 3, 0, 3));
p.addLast("protobufDecoder", new ProtobufDecoder(NetData.NetMessage.getDefaultInstance()));
p.addLast("deflateEncoder", new Lz4FrameEncoder(true));
p.addLast("frameLengthEncoder", new LengthFieldPrepender(3));
p.addLast("protobufEncoder", new ProtobufEncoder());
p.addLast("authenticationHandler", new ClientHandshakeHandler(joinStatus));
p.addLast("connectionHandler", new ServerInfoRequestHandler());
}
use of org.terasology.engine.network.internal.ServerInfoRequestHandler in project Terasology by MovingBlocks.
the class ServerInfoService method requestInfo.
public Future<ServerInfoMessage> requestInfo(final String address, final int port) {
SettableFuture<ServerInfoMessage> resultFuture = SettableFuture.create();
InetSocketAddress remoteAddress = new InetSocketAddress(address, port);
ChannelFuture connectCheck = bootstrap.connect(remoteAddress).addListener(connectFuture -> {
if (!connectFuture.isSuccess()) {
if (connectFuture.cause() != null && connectFuture.cause().getCause() != null) {
// java's network exception.
resultFuture.setException(connectFuture.cause().getCause());
} else if (connectFuture.cause() != null) {
// netty's exception, if it is not java's
resultFuture.setException(connectFuture.cause());
} else {
// fallback exception when connecting not success.
resultFuture.setException(new RuntimeException("Cannot connect to server"));
}
}
});
Channel channel = connectCheck.channel();
channel.closeFuture().addListener(channelFuture -> {
if (channelFuture.isSuccess()) {
ServerInfoRequestHandler handler = channel.pipeline().get(ServerInfoRequestHandler.class);
resultFuture.set(handler.getServerInfo());
} else {
resultFuture.setException(channelFuture.cause());
}
});
return resultFuture;
}
Aggregations