我有一个java应用程序,它使用jsmpp库将SMS发送到SMSC。应用程序连接成功并发送短信。大约一周的正常运行时间后会出现连接问题,在此期间它会发送数千条短信。但几天后应用程序突然开始面临连接问题,有时“否定绑定(bind)响应 0x00045”,有时等待绑定(bind)响应。当我从wireshark检查时,应用程序不断发送查询线路数据包并接收状态为“正常”的响应。这意味着应用程序已连接,但仍在尝试新连接。下面是连接管理的代码。
我调用newSession方法来获取用于短信发送的 session ..
private SMPPSession newSession(BindParameter bindParam) {
SMPPSession tmpSession = null;
dbOperations = new DBOperations();
Settings settings = dbOperations.getSettings();
if (settings == null)
logger.error("ERROR: No settings found to connect to SMSC!");
else {
try {
tmpSession = new SMPPSession(remoteIpAddress, remotePort, bindParam);
tmpSession.addSessionStateListener(new MySessionStateListener());
tmpSession.setMessageReceiverListener(new DeliverReceiptListener());
tmpSession.setEnquireLinkTimer(50000);
tmpSession.setTransactionTimer(5000L);
logger.info("New session established with " + remoteIpAddress + " on port " + remotePort + " as Transmitter");
} catch (Exception er) {
gateway=null;
logger.error("Exception Occurred While making Connection with SMPP Server with IP: " + remoteIpAddress + " and port " + remotePort+" and Error is:"+er.getMessage());
}
}
return tmpSession;
}
public void reconnectAfter(final long timeInMillis) {
final Settings settings = dbOperations.getSettings();
if (settings == null) {
logger.error("No settings found to connect to SMSC!");
return;
}
new Thread() {
@Override
public void run() {
logger.info("Schedule reconnect after " + timeInMillis + " milliseconds");
try {
Thread.sleep(timeInMillis);
} catch (InterruptedException e) {
logger.error(e.getMessage());
}
int attempt = 0;
while (session == null || session.getSessionState().equals(SessionState.CLOSED)) {
try {
logger.info("Reconnecting attempt #" + (++attempt) + "...");
session = newSession(bindParam);
} catch (Exception e) {
logger.error("Failed opening Transmitter connection and bind to " + remoteIpAddress + ":" + remotePort + " ");
logger.error(e.getMessage());
// wait for a second
try {
Thread.sleep(reconnectInterval);
} catch (InterruptedException ee) {
logger.error(e.getMessage());
}
}
}
}
}.start();
}
private class MySessionStateListener implements SessionStateListener {
public void onStateChange(SessionState newState, SessionState oldState, Object o) {
if (newState.equals(SessionState.OPEN)) {
logger.info("TCP connection established with SMSC at address " + remoteIpAddress);
}
if (newState.equals(SessionState.BOUND_TRX)) {
logger.info("SMPP Transceiver connection established with SMSC at address " + remoteIpAddress + " and port " + remotePort);
}
if (newState.equals(SessionState.CLOSED) || newState.equals(SessionState.UNBOUND)) {
logger.error("Connection closed, either by SMSC or there is network problem");
if(newState.equals(SessionState.CLOSED))
logger.error("Connection closed");
else
logger.error("Connection unbound");
logger.info("Reconnecting.......");
reconnectAfter(reconnectInterval);
}
}
}
我不明白为什么此代码在已连接时重试新连接。任何线索表示赞赏。
最佳答案
session 似乎仍然有效。 确保没有僵尸 session ,如果有,则将其全部关闭。它确保查询链接发送停止。
关于java - 使用 jsmpp 与 smpp 服务器绑定(bind)问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37726850/