Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // RAW TSTING
- static int mtu = 9999;
- static String address = "192.168.1.16";
- static int port = 19132;
- static int decrease = 2;
- public static void main(String[] args) {
- // Create boss group for shut down
- InetSocketAddress destination = new InetSocketAddress(address, port);
- EventLoopGroup group = new NioEventLoopGroup();
- try {
- // Store status in an object as it must be final
- final BooleanContainer status = new BooleanContainer(true);
- // Creaete bootstrap and set the options
- final Bootstrap b = new Bootstrap().group(group).channel(NioDatagramChannel.class);
- b.option(ChannelOption.SO_RCVBUF, mtu).option(ChannelOption.SO_SNDBUF, mtu)
- .handler(new SimpleChannelInboundHandler<DatagramPacket>() {
- @Override
- protected void messageReceived(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception {
- // Message was received
- ByteBuf buf = msg.content();
- short id = (short) (buf.readByte() & 0xFF);
- // Make sure it was the correct packet
- if (id == 0x06) {
- buf.readBytes(new byte[25]); // These are not
- // used in this
- // program, only
- // the last 2
- // bytes (The
- // MTU)
- System.out.println("Received response! (MTU: " + buf.readShort() + ")");
- b.option(ChannelOption.SO_SNDBUF, mtu).option(ChannelOption.SO_RCVBUF, mtu);
- // Stop loop and let them know it finished
- // correctly
- status.value = false;
- System.out.println("Connected!");
- } else if (id == 0x1A) {
- // Stop loop but let them know it was the wrong
- // protocol
- System.out.println("Wrong protocol!");
- status.value = false;
- } else {
- System.out.println("Unknown ID! " + id);
- }
- }
- });
- // Bind, get channel, and start the send loop
- Channel c = b.bind(0).sync().channel();
- while (status.value) {
- // Send 0x05 with the specified MTU and protocol
- UnconnectedConnectionRequestOne r = new UnconnectedConnectionRequestOne();
- r.mtuSize = (short) mtu;
- r.protocol = 7;
- r.encode();
- // Set send buffer to the new mtu and send
- b.option(ChannelOption.SO_SNDBUF, (int) r.mtuSize);
- c.writeAndFlush(new DatagramPacket(r.buffer(), destination)).sync();
- // Print message, decrease mtu, and wait .5 seconds to give the
- // server some time to response
- System.out.println("Sent packet with MTU: " + r.mtuSize);
- mtu -= 100L;
- Thread.sleep(500L);
- }
- } catch (Exception e) {
- e.printStackTrace();
- group.shutdownGracefully();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement