设为首页 加入收藏

TOP

Netty5 序列化方式(Jboss Marshalling)(六)
2017-12-14 14:32:09 】 浏览:989
Tags:Netty5 序列化 方式 Jboss Marshalling
  System.out.println("失败服务端消息失败");


                }


            }


        });


//        ctx.writeAndFlush(message);


    }


 


    @Override


    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {


//        ctx.close();


        super.exceptionCaught(ctx, cause);


    }


 


    @Override


    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {


        try {


            Message newMsg = (Message) msg;


            System.out.println("收到服务端的内容" + newMsg);


        }finally {


            ReferenceCountUtil.release(msg);


        }


    }


}


传输的POJO的类,是自定义的封装好的信息。


package com.netty.serialize.message;


 


import java.io.Serializable;


 


/**


 * Created by sdc on 2017/8/26.


 */


public class Message implements Serializable{


 


    /**


    *


    */


    private static final long serialVersionUID = 4923081103118853877L;


 


    private MsgHeader header;


 


    private Object body;


 


    //检验和


//    private byte crcCode;


 


//    public byte getCrcCode() {


//        return crcCode;


//    }


//


//    public void setCrcCode(byte crcCode) {


//        this.crcCode = crcCode;


//    }


 


    public MsgHeader getHeader() {


        return header;


    }


 


    public void setHeader(MsgHeader header) {


        this.header = header;


    }


 


    public Object getBody() {


        return body;


    }


 


    public void setBody(Object body) {


        this.body = body;


    }


 


    @Override


    public String toString() {


        return "Message{" +


                "header=" + header +


                ", body=" + body +


//                ", crcCode=" + crcCode +


                '}';


    }


}


 


 


package com.netty.serialize.message;


import java.io.Serializable;


import java.util.Arrays;


 


/**


 * Created by sdc on 2017/8/26.


 */


public class MsgHeader implements Serializable{


 


    /**


    *


    */


    private static final long serialVersionUID = 4923081103118853877L;


 


    //固定头


    private byte startTag;


 


    //命令码,4位


    private byte[] cmdCode;


 


    //版本 2位


    private byte[] version;


 


    private int length;


 


    public byte[] getVersion() {


        return version;


    }


 


    public void setVersion(byte[] version) {


    &

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

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目