📄 cmpppacket.java
字号:
package com.ekun.sms.cmpp2;
import java.io.*;
import com.ekun.sms.common.BuffMemoUtil;
import com.ekun.common.sms.CmppLinker;
public class CmppPacket
{
public CmppPacket(CmppSocket sock)
{
TotalLength = 0;
CommandID = 0;
SequenceId = 0;
this.sock = sock;
}
/*名称:getCommandID
* 功能:返回包类型
* 输入参数:无
*
* 输出参数:无
*
* 返回值:>= 0:包类型,-1:失败
*/
public int getCommandID()
{
return CommandID;
}
/*名称:getTotalLength
* 功能:返回包总长度
* 输入参数:无
*
* 输出参数:无
*
* 返回值:>=0:包总长度,-1:失败
*/
public int getTotalLength()
{
return TotalLength;
}
/*名称:getSequenceId
* 功能:返回包序列号
* 输入参数:无
*
* 输出参数:无
*
* 返回值:>=0:包序列号,-1:失败
*/
public int getSequenceId()
{
return SequenceId;
}
/*名称:readPacket
* 功能:读取包
* 输入参数:无
*
* 输出参数:无
*
* 返回值:>=0:包序列号,-1:读包失败。
*/
public int readPacket()
{
int reads = -1;
/*读包头*/
headbytes = new byte[12];
int nRet = 0;
try
{
BuffMemoUtil.nRead(headbytes, sock.din);
//分析包总长度
byte tmpTotalLength[] = new byte[4];
CmppCommon.BytesCopy(headbytes, tmpTotalLength, 0, 3, 0);
TotalLength = CmppCommon.Bytes4ToInt(tmpTotalLength);
//读包体
int body_len = TotalLength - 12;
bodybytes = new byte[body_len];
BuffMemoUtil.nRead(bodybytes, sock.din);
/*分析包头*/
//分析包类型
byte tmpCommandID[] = new byte[4];
CmppCommon.BytesCopy(headbytes, tmpCommandID, 4, 7, 0);
CommandID = CmppCommon.Bytes4ToInt(tmpCommandID);
//分析包序列号
byte tmpSequenceId[] = new byte[4];
CmppCommon.BytesCopy(headbytes, tmpSequenceId, 8, 11, 0);
SequenceId = CmppCommon.Bytes4ToInt(tmpSequenceId);
return SequenceId;
}
catch(IOException ioex)
{
return -1;
}
}
/*名称:getPacketBody
* 功能:返回包体
* 输入参数:无
*
* 输出参数:无
*
* 返回值:包体
*/
public byte[] getPacketBody()
{
return bodybytes;
}
private int TotalLength; //包总长
private int CommandID; //包类型
private int SequenceId; //包序列号
private byte bodybytes[]; //包体
private byte headbytes[]; //包头
public CmppSocket sock; //socket链路
/**
* CMPPE LOGIN CMD CODE,登录包命令码
*/
public static final int CMPP_Connect = 1;
/**
* CMPPE LOGIN RESPONSE CMD CODE,登录包命 响应令码
*/
public static final int CMPP_Connect_REP = 0x80000001;
/**
* CMPPE LOGIN LOGOUT CMD CODE,退出登录包命码
*/
public static final int CMPP_Terminate = 2;
/**
* CMPPE LOGIN LOGOUT CMD RESPONSE CODE,退出登录包命响应令码
*/
public static final int CMPP_Terminate_REP = 0x80000002;
/**
* 发送短信包命令码
*/
public static final int CMPP_Submit = 4;
/**
* 发送短信响应包命令码
*/
public static final int CMPP_Submit_REP = 0x80000004;
/**
* 接收短信包命令码
*/
public static final int CMPP_Deliver = 5;
/**
* 接受短信响应包命令码
*/
public static final int CMPP_Deliver_REP = 0x80000005;
/**
* ACTIVE 包命令码
*/
public static final int CMPP_Query = 0x00000006;
public static final int CMPP_Query_REP = 0x80000006;
public static final int CMPP_Cancel = 0x00000007;
public static final int CMPP_Cancel_REP = 0x80000007;
public static final int CMPP_Active_Test = 8;
/**
* ACTIVE响应包命令码
*/
public static final int CMPP_Active_Test_REP = 0x80000008;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -