The previous focus on the Netty adoption of the pipeline processing mode of organization, Channelhandler How to manage, channel status, channel events, such as the upper layer of the architecture design, then how to implement such as socket binding, connection, close and so on, such as the bottom of the operation of the Netty? Not only to apply the API to write programs, but the details superficial understanding. Here the implementation of the socket bindings in the channel under Oio mode is roughly traced, and the logic is the same in the case of NIO (after analysis), but it is different in the place of the thread model. The general process is as follows (detailed source comments, see my GitHub):1. We will provide the corresponding ChannelFactory when we start the client or server through bootstrap;2. In this factory construction process will get the corresponding external resources, and initialize the underlying Channelsink object, otherwise a pipeline default sink is Discardingchannelsink no public;the binding method of 3.Bootstrap opens the channel and then invokes the Bind method of the channel;4. The binding method finally agrees to be completed by the channels auxiliary class;The 4.channels.bind constructs a state event according to the value, and sends it to the bottom downstreamhandler;4. These commands will eventually be completed by the specific channelsink, because the specific channel maintains the Java socket and the input/output stream, so here is the true socket binding.
Netty3 source code Analysis-socket binding implementation principle