设为首页 加入收藏

TOP

Netty5 序列化方式(Jboss Marshalling)(二)
2017-12-14 14:32:09 】 浏览:992
Tags:Netty5 序列化 方式 Jboss Marshalling
w ServerBootstrap();


            sb.group(bossGroup, workerGroup)


                    .channel(NioServerSocketChannel.class)


//                    .childHandler(new ChildChannelHandler())


                    .option(ChannelOption.SO_BACKLOG, 1024)


                    .childHandler(new ChannelInitializer<SocketChannel>() {


                        @Override


                        protected void initChannel(SocketChannel channel) throws Exception {


                            channel.pipeline().addLast(MarshallingCodeCFactory.buildMarshallingDecoder());


                            channel.pipeline().addLast(MarshallingCodeCFactory.buildMarshallingEncoder());


                            channel.pipeline().addLast(new ServerHandler());


                        }


                    })


                    .childOption(ChannelOption.SO_KEEPALIVE, true);


 


            ChannelFuture cf = sb.bind(port).sync();


            System.out.println("服务端已启动");


 


            cf.channel().closeFuture().sync();


        }finally {


            bossGroup.shutdownGracefully();


            workerGroup.shutdownGracefully();


        }


    }


 


    public static class ChildChannelHandler extends ChannelInitializer {


 


        protected void initChannel(Channel channel) throws Exception {


            channel.pipeline().addLast(MarshallingCodeCFactory.buildMarshallingDecoder());


            channel.pipeline().addLast(MarshallingCodeCFactory.buildMarshallingEncoder());


            channel.pipeline().addLast(new ServerHandler());


        }


 


    }


 


    public static void main(String[] args){


        try {


            new MsgServer().bind(8080);


        } catch (Exception e) {


            e.printStackTrace();


        }


    }


}


 


 


package com.netty.serialize.handler;


 


import com.netty.serialize.message.Message;


import com.netty.serialize.message.MsgHeader;


import io.netty.channel.ChannelHandlerAdapter;


import io.netty.channel.ChannelHandlerContext;


 


/**


 * 用于测试服务端实现的


 * Created by sdc on 2017/8/29.


 */


public class ServerHandler extends ChannelHandlerAdapter{


&

首页 上一页 1 2 3 4 5 6 下一页 尾页 2/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Python模块入门教程之smtplib 邮.. 下一篇Java 设计模式之适配器模式

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目