Home / Class/ Http3ClientExample Class — netty Architecture

Http3ClientExample Class — netty Architecture

Architecture documentation for the Http3ClientExample class in Http3ClientExample.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  0ae7f510_86e0_e911_d0aa_4496103975a1["Http3ClientExample"]
  f930938e_dd0d_7b1b_fb70_66e6f6f26a8a["Http3ClientExample.java"]
  0ae7f510_86e0_e911_d0aa_4496103975a1 -->|defined in| f930938e_dd0d_7b1b_fb70_66e6f6f26a8a
  9bb43cbe_edd1_d231_9050_19839a0b6545["Http3ClientExample()"]
  0ae7f510_86e0_e911_d0aa_4496103975a1 -->|method| 9bb43cbe_edd1_d231_9050_19839a0b6545
  409cb9bc_453a_ab7d_24c8_f2ea25d3a0da["main()"]
  0ae7f510_86e0_e911_d0aa_4496103975a1 -->|method| 409cb9bc_453a_ab7d_24c8_f2ea25d3a0da

Relationship Graph

Source Code

codec-http3/src/test/java/io/netty/handler/codec/http3/example/Http3ClientExample.java lines 44–112

public final class Http3ClientExample {
    private Http3ClientExample() { }

    public static void main(String... args) throws Exception {
        EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory());

        try {
            QuicSslContext context = QuicSslContextBuilder.forClient()
                    .trustManager(InsecureTrustManagerFactory.INSTANCE)
                    .applicationProtocols(Http3.supportedApplicationProtocols()).build();
            ChannelHandler codec = Http3.newQuicClientCodecBuilder()
                    .sslContext(context)
                    .maxIdleTimeout(5000, TimeUnit.MILLISECONDS)
                    .initialMaxData(10000000)
                    .initialMaxStreamDataBidirectionalLocal(1000000)
                    .build();

            Bootstrap bs = new Bootstrap();
            Channel channel = bs.group(group)
                    .channel(NioDatagramChannel.class)
                    .handler(codec)
                    .bind(0).sync().channel();

            QuicChannel quicChannel = QuicChannel.newBootstrap(channel)
                    .handler(new Http3ClientConnectionHandler())
                    .remoteAddress(new InetSocketAddress(NetUtil.LOCALHOST4, Http3ServerExample.PORT))
                    .connect()
                    .get();

            QuicStreamChannel streamChannel = Http3.newRequestStream(quicChannel,
                    new Http3RequestStreamInboundHandler() {
                        @Override
                        protected void channelRead(ChannelHandlerContext ctx, Http3HeadersFrame frame) {
                            ReferenceCountUtil.release(frame);
                        }

                        @Override
                        protected void channelRead(ChannelHandlerContext ctx, Http3DataFrame frame) {
                            System.err.print(frame.content().toString(CharsetUtil.US_ASCII));
                            ReferenceCountUtil.release(frame);
                        }

                        @Override
                        protected void channelInputClosed(ChannelHandlerContext ctx) {
                            ctx.close();
                        }
                    }).sync().getNow();

            // Write the Header frame and send the FIN to mark the end of the request.
            // After this its not possible anymore to write any more data.
            Http3HeadersFrame frame = new DefaultHttp3HeadersFrame();
            frame.headers().method("GET").path("/")
                    .authority(NetUtil.LOCALHOST4.getHostAddress() + ":" + Http3ServerExample.PORT)
                    .scheme("https");
            streamChannel.writeAndFlush(frame)
                    .addListener(QuicStreamChannel.SHUTDOWN_OUTPUT).sync();

            // Wait for the stream channel and quic channel to be closed (this will happen after we received the FIN).
            // After this is done we will close the underlying datagram channel.
            streamChannel.closeFuture().sync();

            // After we received the response lets also close the underlying QUIC channel and datagram channel.
            quicChannel.close().sync();
            channel.close().sync();
        } finally {
            group.shutdownGracefully();
        }
    }
}

Frequently Asked Questions

What is the Http3ClientExample class?
Http3ClientExample is a class in the netty codebase, defined in codec-http3/src/test/java/io/netty/handler/codec/http3/example/Http3ClientExample.java.
Where is Http3ClientExample defined?
Http3ClientExample is defined in codec-http3/src/test/java/io/netty/handler/codec/http3/example/Http3ClientExample.java at line 44.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free