2016-06-09 14 views
0

jsmpp 라이브러리를 사용하여 SMSC에 SMS를 보내는 Java 응용 프로그램이 있습니다. 응용 프로그램이 성공적으로 연결되어 SMS를 보냅니다. 연결 문제는 일주일 정도 지나면 발생합니다.이 시간 동안 수천 개의 SMS를 보냅니다. 하지만 갑자기 며칠 후 응용 프로그램이 연결 문제에 직면하기 시작합니다. '부정적인 바인드 응답 0x00045'와 바인드 응답을 기다리는 시간이 있습니다. wireshark에서 확인하면 응용 프로그램은 끊임없이 회선 패킷을 보내고 상태가 'OK'인 응답을받습니다. 즉, 응용 프로그램이 연결되어 있지만 새로운 연결을 시도 중입니다. 아래는 연결 관리를위한 코드입니다.jsmpp를 사용하여 smpp 서버에 바인딩 문제

나는

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); 
      } 
     } 
    } 

.. 보내는 SMS에 대한 세션을 얻을 수 newSession 메소드를 호출 난 이미 연결되어있을 때이 코드는 새로운 연결을 시도하지 왜. 어떤 단서가 인정됩니다.

답변

1

세션이 여전히 유효합니다. 좀비 세션이 없는지 확인한 다음 좀비 세션이 있으면 모두 닫으십시오. 그것은 링크를 보내 중지 문의하십시오.

+0

세션이 여전히 유효하면 SessionStateListener에서 reconnectAfter 메서드가 호출되는 이유는 무엇입니까? 위의 코드에 대한 변경 사항을 제안 하시겠습니까? 좀비 세션이 있는지 어떻게 알 수 있습니까? – sikander