资源简介
mina2 cs 客户端服务器通信 已经实现完整通信代码
代码片段和文件信息
package com.minaqq.charset;
import java.nio.ByteOrder;
import java.nio.charset.Charset;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
import com.minaqq.domain.MsgPack;
/**
* @see 协议解码
* @author Herman.Xiong
* @date 2014年6月11日 16:47:24
*/
public class MsgProtocolDecoder extends CumulativeProtocolDecoder {
private Charset charset=null;
public MsgProtocolDecoder() {
this(Charset.defaultCharset());
}
public MsgProtocolDecoder(Charset charset) {
this.charset = charset;
}
/*public void decode1(IoSession is IoBuffer buf ProtocolDecoderOutput out)
throws Exception {
buf.order(ByteOrder.LITTLE_ENDIAN);
MsgPack mp=new MsgPack();
//获取消息的内容长度
mp.setMsgLength(buf.getInt());
//获取消息的功能函数
mp.setMsgMethod(buf.getInt());
byte[] msg=new byte[mp.getMsgLength()];
buf.get(msg);
mp.setMsgPack(new String(msgcharset));
buf.flip();
out.write(mp);
}
*/
public void dispose(IoSession arg0) throws Exception {
}
public void finishDecode(IoSession arg0 ProtocolDecoderOutput arg1)
throws Exception {
}
protected boolean doDecode(IoSession session IoBuffer ioBuffer ProtocolDecoderOutput out) throws Exception {
ioBuffer.order(ByteOrder.LITTLE_ENDIAN);
//接收到的数据一点一点的存进缓冲区,
//ioBuffer.capacity的容量是根据接收的数据自动增长的
MsgPack mp = (MsgPack) session.getAttribute(“nac-msg-pack“); // 从session对象中获取“xhs-upload”属性值
//System.out.println(“**********doDecode1*****“+ioBuffer.toString());
//System.out.println(“1*****************“+ioBuffer.remaining()+“**“+ioBuffer.capacity());
if(null==mp){
if (ioBuffer.remaining() >= 8) {
//取消息体长度
int msgLength = ioBuffer.getInt();
int msgMethod = ioBuffer.getInt();
mp=new MsgPack();
mp.setMsgLength(msgLength);
mp.setMsgMethod(msgMethod);
// System.out.println(“2*****************“+ioBuffer.remaining()+“***“+mp.getMsgLength());
session.setAttribute(“nac-msg-pack“mp);
return true;
}
//System.out.println(“aaaaaaaaaaaa“);
return false;
}
//当缓冲区除去前八个字节剩余的字节大于或等于本条消息的长度时就取出否则就反复回调此方法,直到长度够解码
//如果本次解码成功,就自动清空本消息占得缓存
//当你认为读取到的数据已经够本次消息解码了,也就是够本次消息的长度,那么就返回true,否则就返回false
if(ioBuffer.remaining()>=mp.getMsgLength()){
//System.out.println(“3*****************“+ioBuffer.remaining()+“***“+mp.getMsgLength());
byte [] msgPack=new byte[mp.getMsgLength()];
//从缓冲区读取mp.getMsgLength()个字节的数据填充进数组
ioBuffer.get(msgPack);
mp.setMsgPack(new String(msgPackcharset));
//System.out.println(“**********doDecode3*****“+mp.toString());
session.removeAttribute(“nac-msg-pack“);
out.write(mp);
return true;
}
//System.out.println(“aaaaaaaaaaaa1“);
return false;
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2139 2014-06-09 16:20 MINA2\.classpath
文件 383 2013-11-26 10:56 MINA2\.project
文件 88 2014-06-09 11:42 MINA2\.settings\org.eclipse.core.resources.prefs
文件 629 2013-11-26 10:56 MINA2\.settings\org.eclipse.jdt.core.prefs
文件 2689 2015-05-31 12:58 MINA2\bin\com\minaqq\charset\MsgProtocolDecoder.class
文件 2117 2015-05-31 12:58 MINA2\bin\com\minaqq\charset\MsgProtocolEncoder.class
文件 2914 2015-05-31 12:58 MINA2\bin\com\minaqq\client\ClientMsgProtocol.class
文件 1957 2015-05-31 12:58 MINA2\bin\com\minaqq\client\TimeClientHandler.class
文件 1539 2015-05-31 12:58 MINA2\bin\com\minaqq\domain\MsgPack.class
文件 1198 2015-05-31 12:58 MINA2\bin\com\minaqq\protocol\MsgProtocol.class
文件 1866 2015-05-31 12:58 MINA2\bin\com\minaqq\server\KeepAliveMessageFactoryImpl.class
文件 1763 2015-05-31 12:58 MINA2\bin\com\minaqq\server\KeepAliveRequestTimeoutHandlerImpl$1.class
文件 1586 2015-05-31 12:58 MINA2\bin\com\minaqq\server\KeepAliveRequestTimeoutHandlerImpl.class
文件 1618 2015-05-31 12:58 MINA2\bin\com\minaqq\server\ServerMessageHandler$1.class
文件 3305 2015-05-31 12:58 MINA2\bin\com\minaqq\server\ServerMessageHandler.class
文件 3622 2015-05-31 12:58 MINA2\bin\com\minaqq\server\ServerMsgProtocol.class
文件 864 2015-05-31 12:58 MINA2\bin\com\minaqq\test\MsgClientTest.class
文件 889 2015-05-31 12:58 MINA2\bin\com\minaqq\test\MsgServerTest.class
文件 1528 2015-05-31 12:58 MINA2\bin\com\minaqq\utils\xm
文件 1478 2015-05-31 12:58 MINA2\bin\com\minaqq\worker\ClientSendMsgThread.class
文件 2362 2015-05-31 12:58 MINA2\bin\com\minaqq\worker\ServerSendMsgThread.class
文件 2429 2013-12-05 16:28 MINA2\bin\log4j.properties
文件 284220 2014-06-09 11:57 MINA2\lib\commons-lang-2.6.jar
文件 31605 2014-06-09 11:57 MINA2\lib\commons-logging-1.0.3.jar
文件 614203 2014-06-09 11:57 MINA2\lib\javassist-3.11.0.GA.jar
文件 544021 2014-06-09 11:57 MINA2\lib\javassist-3.7.ga.jar
文件 17289 2014-06-09 11:57 MINA2\lib\jcl-over-slf4j-1.6.6.jar
文件 69578 2014-06-09 11:57 MINA2\lib\jzlib-1.1.1.jar
文件 644783 2014-06-09 11:56 MINA2\lib\mina-core-2.0.7.jar
文件 142581 2014-06-09 11:56 MINA2\lib\mina-example-2.0.7.jar
............此处省略62个文件信息
- 上一篇:pl2303 xp系统驱动
- 下一篇:word2vec 源码和pdf
相关资源
- Cimetrix SECS/GEM TESTConnect
- 深入理解计算机系统 lab
- From Mathematics to Generic Programming 数学与
- VCS DVE中文指导手册
- Applied Bayesian Statistics---With R and OpenB
- Paul S. Steif Mechanics of Materials 2012
- csp共同空间模式
- radar cross section,RCS讲义,AD报告
- vcs user guide267169
- Mathematical methods using Mathematica for st
- RHCSA笔记.pdf
- PCL点云库SACSegmentation用法demo
- The Physics of Solar Cells(Jenny Nelson)
- Assembly-CSharp.rar
- 中文NCSentry
- 《深入理解计算机系统》随书代码
- Discrete Mathematics with Applications 4th edi
- tcs230颜色识别传感器
- [mobi资源+pdf] Network Algorithmics
- mathematics for computer science.pdf
- MSP430 Microcontroller Basics.pdf
- 2天驾驭DIV+CSS(全新发布2.0.3版本)
- [Damelio_Robert]_The_Basics_of_Process_Mapping
- ecshop2.7.3繁體中文UTF-8 BY we-shop.net
- Blockchain Basics A Non-Technical Introduction
- The Magic of Computer Graphics 无水印pdf
- Mathematics for 3D Game Programming and Comput
- Mathematical Structures for Computer Graphics 无
- Interactive Computer Graphics(6th) 无水印
- TensorFlow Powerful Predictive Analytics with
评论
共有 条评论