diff --git a/server/netty/src/com/riiablo/net/reliable/TestClient.java b/server/netty/src/com/riiablo/net/reliable/TestClient.java index 4aa6419f..bf9a1408 100644 --- a/server/netty/src/com/riiablo/net/reliable/TestClient.java +++ b/server/netty/src/com/riiablo/net/reliable/TestClient.java @@ -5,8 +5,6 @@ import io.netty.bootstrap.Bootstrap; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; @@ -56,31 +54,12 @@ public class TestClient extends ApplicationAdapter implements PacketProcessor { endpoint = new ReliableEndpoint(ch, TestClient.this); ch.pipeline() .addLast(new EndpointedChannelHandler<>(DatagramPacket.class, endpoint)) - .addLast(new ChannelInboundHandlerAdapter() { - @Override - public void channelActive(ChannelHandlerContext ctx) throws Exception { - init(); - ctx.pipeline().remove(this); - } - - void init() { - InetSocketAddress remoteAddress = (InetSocketAddress) endpoint.channel().remoteAddress(); - Gdx.app.log(TAG, "Sending Connection packet to " + remoteAddress.getHostString() + ":" + remoteAddress.getPort()); - - FlatBufferBuilder builder = new FlatBufferBuilder(); - Connection.startConnection(builder); - int dataOffset = Connection.endConnection(builder); - int offset = Netty.createNetty(builder, NettyData.Connection, dataOffset); - Netty.finishNettyBuffer(builder, offset); - - endpoint.sendMessage(QoS.Unreliable, builder.dataBuffer()); - } - }) ; } }); - ChannelFuture f = b.connect("localhost", TestServer.PORT); + ChannelFuture f = b.connect("localhost", TestServer.PORT).sync(); + sendPacket(); f.channel().closeFuture().sync(); } catch (Throwable t) { Gdx.app.error(TAG, t.getMessage(), t); @@ -89,6 +68,19 @@ public class TestClient extends ApplicationAdapter implements PacketProcessor { } } + private void sendPacket() { + InetSocketAddress remoteAddress = (InetSocketAddress) endpoint.channel().remoteAddress(); + Gdx.app.log(TAG, "Sending Connection packet to " + remoteAddress.getHostString() + ":" + remoteAddress.getPort()); + + FlatBufferBuilder builder = new FlatBufferBuilder(); + Connection.startConnection(builder); + int dataOffset = Connection.endConnection(builder); + int offset = Netty.createNetty(builder, NettyData.Connection, dataOffset); + Netty.finishNettyBuffer(builder, offset); + + endpoint.sendMessage(QoS.Unreliable, builder.dataBuffer()); + } + @Override public void render() { endpoint.update(Gdx.graphics.getDeltaTime()); diff --git a/server/netty/src/com/riiablo/net/tcp/TestClient.java b/server/netty/src/com/riiablo/net/tcp/TestClient.java index 40624503..1b437ef0 100644 --- a/server/netty/src/com/riiablo/net/tcp/TestClient.java +++ b/server/netty/src/com/riiablo/net/tcp/TestClient.java @@ -5,8 +5,6 @@ import io.netty.bootstrap.Bootstrap; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; @@ -58,31 +56,12 @@ public class TestClient extends ApplicationAdapter implements PacketProcessor { endpoint = new TcpEndpoint(ch, TestClient.this); ch.pipeline() .addLast(new EndpointedChannelHandler<>(ByteBuf.class, endpoint)) - .addLast(new ChannelInboundHandlerAdapter() { - @Override - public void channelActive(ChannelHandlerContext ctx) throws Exception { - init(); - ctx.pipeline().remove(this); - } - - void init() { - InetSocketAddress remoteAddress = (InetSocketAddress) endpoint.channel().remoteAddress(); - Gdx.app.log(TAG, "Sending Connection packet to " + remoteAddress.getHostString() + ":" + remoteAddress.getPort()); - - FlatBufferBuilder builder = new FlatBufferBuilder(); - Connection.startConnection(builder); - int dataOffset = Connection.endConnection(builder); - int offset = Netty.createNetty(builder, NettyData.Connection, dataOffset); - Netty.finishNettyBuffer(builder, offset); - - endpoint.sendMessage(QoS.Unreliable, builder.dataBuffer()); - } - }) ; } }); ChannelFuture f = b.connect("localhost", TestServer.PORT).sync(); + sendPacket(); f.channel().closeFuture().sync(); } catch (Throwable t) { Gdx.app.error(TAG, t.getMessage(), t); @@ -92,6 +71,19 @@ public class TestClient extends ApplicationAdapter implements PacketProcessor { } } + private void sendPacket() { + InetSocketAddress remoteAddress = (InetSocketAddress) endpoint.channel().remoteAddress(); + Gdx.app.log(TAG, "Sending Connection packet to " + remoteAddress.getHostString() + ":" + remoteAddress.getPort()); + + FlatBufferBuilder builder = new FlatBufferBuilder(); + Connection.startConnection(builder); + int dataOffset = Connection.endConnection(builder); + int offset = Netty.createNetty(builder, NettyData.Connection, dataOffset); + Netty.finishNettyBuffer(builder, offset); + + endpoint.sendMessage(QoS.Unreliable, builder.dataBuffer()); + } + @Override public void render() { endpoint.update(Gdx.graphics.getDeltaTime());