SMSをSMSCに送信するためにjsmppライブラリを使用するJavaアプリケーションがあります。アプリケーションは正常に接続し、SMS を送信します。接続の問題は、1 週間ほどの稼働時間後に発生し、この稼働時間中に何千もの SMS が送信されます。しかし、数日後、突然、アプリケーションが接続の問題に直面し始め、「ネガティブ バインド応答 0x00045」が発生し、バインド応答を待機することがあります。Wireshark から確認すると、アプリケーションは常に問い合わせライン パケットを送信し、ステータスが「OK」の応答を受信します。これは、アプリケーションが接続されているが、まだ新しい接続を試みていることを意味します。以下は、接続管理のコードです。
SMS 送信用のセッションを取得するために newSession メソッドを呼び出します。
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);
}
}
}
既に接続されているときに、このコードが新しい接続を再試行する理由はわかりません。手がかりをいただければ幸いです。