因业务需要,需要开发一个引擎(采用JAVA),来解析SMPP包然后经过一系列处理入REDIS队列。看到解包,想到之前用C/C++进行SOCKET编程时,事先约定好,头4个字节作为一个整形字段,代表整个字节组的长度,后面依次其他。解析时候先解析出头部得到字节总长度,和获取到的字节数组比对看是否相等,然后依次解析后面字段。我想解析SMPP包也类似,所以就网上搜索一下SMPP的资料,摘抄如下:
消息头语法
字段
|
长度(字节)
|
类型
|
Command Length
|
4
|
Integer
|
Command ID
|
4
|
Integer
|
Command_status
|
4
|
Integer
|
Sequence No.
|
4
|
Integer
|
Optional Message Body
|
可变
|
混合
|
具体字段描述说明:
Command Length:整个包的长度(包括该字段本身)。。。看到这基本上明白,也是依次解析字段的。现在模拟一下,发包和解包的过程。
1 首先创建一个线程池来监听GlobalProperties.mClientPort端口。
private final ExecutorService execService = Executors.newSingleThreadExecutor();
SMPPServerSimulator smppServerSim = new SMPPServerSimulator(GlobalProperties.mClientPort);
execService.execute(smppServerSim);
1.1 SMPPServerSimulator 运行时会创建ServerSocket来监听GlobalProperties.mClientPort端口
public void run() {
try {
SMPPServerSessionListener sessionListener = new SMPPServerSessionListener(port);
logger.info("Listening on port {}", port);
while (true) {