📄 cngpsmproxy.java
字号:
package com.grail.smproxy;
import java.io.IOException;
import java.util.Map;
import com.grail.comm.cngp.CNGPConnection;
import com.grail.comm.cngp.CNGPTransaction;
import com.grail.comm.cngp.message.CNGPDeliverMessage;
import com.grail.comm.cngp.message.CNGPDeliverRespMessage;
import com.grail.comm.cngp.message.CNGPMessage;
import com.grail.util.Args;
/**
* <p>
* Title: smgw 项目
* </p>
*
* <p>
* Description:
* </p>
*
* <p>
* Copyright: Copyright (c) 2004 arefa
* </p>
*
* <p>
* Company: arefa
* </p>
*
* <p>
* 所有类均以开源项目为基础,感谢他们对 JAVA 世界作出的贡献
* </p>
*
* @author lyw / 刘有为
* @version 1.0
*/
public class CNGPSMProxy {
private CNGPConnection conn;
public CNGPSMProxy(Map args) {
this(new Args(args));
}
public CNGPSMProxy(Args args) {
conn = new CNGPConnection(args);
conn.addEventListener(new CNGPEventAdapter(this));
conn.waitAvailable();
if (!conn.available())
throw new IllegalStateException(conn.getError());
else
return;
}
/**
* 发送信息
* @param message 消息内容对象
* @return CNGPMessage
* @throws IOException
*/
public CNGPMessage send(CNGPMessage message) throws IOException {
if (message == null)
return null;
CNGPTransaction t = (CNGPTransaction) conn.createChild();
try {
t.send(message);
t.waitResponse();
CNGPMessage rsp = t.getResponse();
CNGPMessage cngpmessage = rsp;
return cngpmessage;
} finally {
t.close();
}
}
/**
* 端口连接时的处理方法
*/
public void onTerminate() {
}
/**
* 接受信息方法
* @param msg
* @return
*/
public CNGPMessage onDeliver(CNGPDeliverMessage msg) {
CNGPMessage message = new CNGPDeliverRespMessage(msg.getMsgId(), 0);
byte[] deliver = msg.getMsgId();
return message;
}
/**
* 关闭连接
*/
public void close() {
conn.close();
}
/**
* 返回连接
* @return CNGPConnection
*/
public CNGPConnection getConn() {
return conn;
}
/**
* 返回连接状态
* @return String
*/
public String getConnState() {
return conn.getError();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -