解决方案 »
- 腾讯微博调用statuses/home_timeline API的时候报错 来看下
- 大家觉得这个设计可行吗
- EhCache和OScache哪个好些啊
- 悬赏100元人民币+80分,求基于servicemix开发的进行简单数据库操作的source!!!!
- 商品种类,每个种类都有不同的属性的建模问题
- 学JAVA,需要安装什么(刚学)
- 关于Access存储对象的问题
- 在运行远程对象注册到RMI的名称空间时,不知道为什么总是提示远程对象的客户端代理不存在(如:CompanyImpl_Stub)
- 为什么jcreatepro2.5不能编译servlet的程序(难道是不支持吗)
- FTPClient本地上传文件正常,项目发布到服务器上,上传失败
- WEBLOGIC提示:stax不能用,请换woodstox, 怎么换?
- 我现在写一个java与松下plc通讯,不知道怎么向plc发送指令和接受指令
2 在包头使用长度位,从包头开始N字节,是一个逻辑包。所以,你选用的编码/解码,要配对的,编码时候,换行不是正文,那么你解码的地方,也要做相应处理。
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ProtocolCodecFactory() { @Override
public ProtocolEncoder getEncoder(IoSession arg0) throws Exception { ProtocolEncoderAdapter p = new ProtocolEncoderAdapter() { @Override
public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
System.out.println(message);
if(message instanceof String){
IoBuffer buffer = IoBuffer.wrap(((String)message).getBytes());
buffer.position(((String)message).getBytes().length);
buffer.flip();
out.write(buffer);
}
out.flush();
}
}; return p;
} @Override
public ProtocolDecoder getDecoder(IoSession arg0) throws Exception { CumulativeProtocolDecoder c = new CumulativeProtocolDecoder() { @Override
protected boolean doDecode(IoSession session, IoBuffer buffer, ProtocolDecoderOutput out)
throws Exception {
return true;
}
};
return c;
}
}));
acceptor.setHandler(new IoHandlerAdapter() { @Override
public void sessionOpened(IoSession session) throws Exception {
session.write("hello===============");
session.write("hello===============>");
}
});
try {
acceptor.bind(new InetSocketAddress(60000));
} catch (IOException e) {
e.printStackTrace();
}