Home / Class/ SpdyClient Class — netty Architecture

SpdyClient Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  1583668c_c478_805d_bddb_bdf5a9931203["SpdyClient"]
  75d2d35e_b5e9_2379_1f5b_e814659f1311["SpdyClient.java"]
  1583668c_c478_805d_bddb_bdf5a9931203 -->|defined in| 75d2d35e_b5e9_2379_1f5b_e814659f1311
  6cfd3ea7_c058_400c_1f90_c0a2dba57776["main()"]
  1583668c_c478_805d_bddb_bdf5a9931203 -->|method| 6cfd3ea7_c058_400c_1f90_c0a2dba57776

Relationship Graph

Source Code

example/src/main/java/io/netty/example/spdy/client/SpdyClient.java lines 49–102

public final class SpdyClient {

    static final String HOST = System.getProperty("host", "127.0.0.1");
    static final int PORT = Integer.parseInt(System.getProperty("port", "8443"));

    public static void main(String[] args) throws Exception {
        // Configure SSL.
        final SslContext sslCtx = SslContextBuilder.forClient()
            .trustManager(InsecureTrustManagerFactory.INSTANCE)
            .applicationProtocolConfig(new ApplicationProtocolConfig(
                        Protocol.ALPN,
                        // NO_ADVERTISE is currently the only mode supported by both OpenSsl and JDK providers.
                        SelectorFailureBehavior.NO_ADVERTISE,
                        // ACCEPT is currently the only mode supported by both OpenSsl and JDK providers.
                        SelectedListenerFailureBehavior.ACCEPT,
                        ApplicationProtocolNames.SPDY_3_1,
                        ApplicationProtocolNames.HTTP_1_1))
            .build();

        HttpResponseClientHandler httpResponseHandler = new HttpResponseClientHandler();
        EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());

        try {
            Bootstrap b = new Bootstrap();
            b.group(group);
            b.channel(NioSocketChannel.class);
            b.option(ChannelOption.SO_KEEPALIVE, true);
            b.remoteAddress(HOST, PORT);
            b.handler(new SpdyClientInitializer(sslCtx, httpResponseHandler));

            // Start the client.
            Channel channel = b.connect().syncUninterruptibly().channel();
            System.out.println("Connected to " + HOST + ':' + PORT);

            // Create a GET request.
            HttpRequest request = new DefaultFullHttpRequest(
                    HttpVersion.HTTP_1_1, HttpMethod.GET, "", Unpooled.EMPTY_BUFFER);
            request.headers().set(HttpHeaderNames.HOST, HOST);
            request.headers().set(HttpHeaderNames.ACCEPT_ENCODING, HttpHeaderValues.GZIP);

            // Send the GET request.
            channel.writeAndFlush(request).sync();

            // Waits for the complete HTTP response
            httpResponseHandler.queue().take().sync();
            System.out.println("Finished SPDY HTTP GET");

            // Wait until the connection is closed.
            channel.close().syncUninterruptibly();
        } finally {
            group.shutdownGracefully();
        }
    }
}

Frequently Asked Questions

What is the SpdyClient class?
SpdyClient is a class in the netty codebase, defined in example/src/main/java/io/netty/example/spdy/client/SpdyClient.java.
Where is SpdyClient defined?
SpdyClient is defined in example/src/main/java/io/netty/example/spdy/client/SpdyClient.java at line 49.

Analyze Your Own Codebase

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

Try Supermodel Free