netty-1. From the most simple example

(original)

The first chapter, from the most simple example

1, netty is doing, how to use, not introduced here, starting with an example to understand it,

Above 5.0 netty it has been abandoned, the following examples starting from 4.1.10.Final version.

2, a total of three categories

1> TestServer for starting a service, there are two EventLoopGroup, bossGroup and workerGroup, bossGroup receiving a request from a client, and then processing the requests workerGroup onward transmission.

2> TestServerInitializer server initialization, the processing for collecting client data handling, and to customize

3> TestHttpServerHandler custom processor for responding to client requests

 

Key Code:

 

test:

The main method of operation TestServer

Enter the address in the browser: HTTP: // localhost: 8090 /

If the response appears hello world, there is no background error, indicating a successful start, completed the first simplest netty example.

3, there will be two requests when accessed through a browser, a request is our own, is a built-in browser Get the icon of the request:




The TestHttpServerHandler transformation as follows:

Download demo

Guess you like

Origin www.cnblogs.com/LeeScofiled/p/11250502.html