Home / Function/ main() — netty Function Reference

main() — netty Function Reference

Architecture documentation for the main() function in TcpDnsServer.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  e2c04177_18f3_85bf_661f_a4c1ab3458d3["main()"]
  2163a46b_2065_a299_066e_84c6fa29ec99["TcpDnsServer"]
  e2c04177_18f3_85bf_661f_a4c1ab3458d3 -->|defined in| 2163a46b_2065_a299_066e_84c6fa29ec99
  1404dde2_6698_e33d_44ec_c96c503e47f2["clientQuery()"]
  e2c04177_18f3_85bf_661f_a4c1ab3458d3 -->|calls| 1404dde2_6698_e33d_44ec_c96c503e47f2
  style e2c04177_18f3_85bf_661f_a4c1ab3458d3 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

example/src/main/java/io/netty/example/dns/tcp/TcpDnsServer.java lines 61–111

    public static void main(String[] args) throws Exception {
        ServerBootstrap bootstrap = new ServerBootstrap().group(
                new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()))
                .channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new ChannelInitializer<Channel>() {
                    @Override
                    protected void initChannel(Channel ch) throws Exception {
                        ch.pipeline().addLast(new TcpDnsQueryDecoder(), new TcpDnsResponseEncoder(),
                                new SimpleChannelInboundHandler<DnsQuery>() {
                                    @Override
                                    protected void channelRead0(ChannelHandlerContext ctx,
                                                                DnsQuery msg) throws Exception {
                                        DnsQuestion question = msg.recordAt(DnsSection.QUESTION);
                                        System.out.println("Query domain: " + question);

                                        //always return 192.168.1.1
                                        ctx.writeAndFlush(newResponse(msg, question, 600, QUERY_RESULT));
                                    }

                                    private DefaultDnsResponse newResponse(DnsQuery query,
                                                                           DnsQuestion question,
                                                                           long ttl, byte[]... addresses) {
                                        DefaultDnsResponse response = new DefaultDnsResponse(query.id());
                                        response.addRecord(DnsSection.QUESTION, question);

                                        for (byte[] address : addresses) {
                                            DefaultDnsRawRecord queryAnswer = new DefaultDnsRawRecord(
                                                    question.name(),
                                                    DnsRecordType.A, ttl, Unpooled.wrappedBuffer(address));
                                            response.addRecord(DnsSection.ANSWER, queryAnswer);
                                        }
                                        return response;
                                    }
                                });
                    }
                });
        final Channel channel = bootstrap.bind(DNS_SERVER_PORT).channel();
        Executors.newSingleThreadScheduledExecutor().schedule(new Runnable() {
            @Override
            public void run() {
                try {
                    clientQuery();
                    channel.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, 1000, TimeUnit.MILLISECONDS);
        channel.closeFuture().sync();
    }

Domain

Subdomains

Frequently Asked Questions

What does main() do?
main() is a function in the netty codebase, defined in example/src/main/java/io/netty/example/dns/tcp/TcpDnsServer.java.
Where is main() defined?
main() is defined in example/src/main/java/io/netty/example/dns/tcp/TcpDnsServer.java at line 61.
What does main() call?
main() calls 1 function(s): clientQuery.

Analyze Your Own Codebase

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

Try Supermodel Free