Search in sources :

Example 1 with HelloWorldClientHandler

use of org.ko.netty.t1.handler.HelloWorldClientHandler in project tutorials-java by Artister.

the class ClientChannelInitializer method initChannel.

protected void initChannel(SocketChannel socketChannel) throws Exception {
    /**
     * Channel---通道
     * ChannelPipeline是ChannelHandler的容器
     * 负责ChannelHandler的管理和事件拦截与调度
     * 类似于Servlet 和Filter 过滤器
     * 方便事件的拦截和用户业务逻辑的定制
     */
    ChannelPipeline pipeline = socketChannel.pipeline();
    /**
     * 这个地方的 必须和服务端对应上。否则无法正常解码和编码
     * 解码和编码 我将会在下一节为大家详细的讲解。暂时不做详细的描述
     */
    pipeline.addLast("decoder", new StringDecoder());
    pipeline.addLast("encoder", new StringEncoder());
    // 我们自己的handler
    pipeline.addLast("handler", new HelloWorldClientHandler());
}
Also used : StringEncoder(io.netty.handler.codec.string.StringEncoder) HelloWorldClientHandler(org.ko.netty.t1.handler.HelloWorldClientHandler) StringDecoder(io.netty.handler.codec.string.StringDecoder) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 2 with HelloWorldClientHandler

use of org.ko.netty.t1.handler.HelloWorldClientHandler in project tutorials-java by Artister.

the class ClientChannelInitializer method initChannel.

protected void initChannel(SocketChannel socketChannel) throws Exception {
    ChannelPipeline pipeline = socketChannel.pipeline();
    pipeline.addLast("decoder", new StringDecoder());
    pipeline.addLast("encoder", new StringEncoder());
    // 客户端的逻辑
    pipeline.addLast("handler", new HelloWorldClientHandler());
}
Also used : StringEncoder(io.netty.handler.codec.string.StringEncoder) HelloWorldClientHandler(org.ko.netty.t3.handler.HelloWorldClientHandler) StringDecoder(io.netty.handler.codec.string.StringDecoder) ChannelPipeline(io.netty.channel.ChannelPipeline)

Aggregations

ChannelPipeline (io.netty.channel.ChannelPipeline)2 StringDecoder (io.netty.handler.codec.string.StringDecoder)2 StringEncoder (io.netty.handler.codec.string.StringEncoder)2 HelloWorldClientHandler (org.ko.netty.t1.handler.HelloWorldClientHandler)1 HelloWorldClientHandler (org.ko.netty.t3.handler.HelloWorldClientHandler)1