2013-02-20 3 views
0
내가이 작품의 몇 시간 client..for SMSC를 만들 열기 SMPP의 LOGICA 라이브러리를 사용하여이 오류

java.net.SocketException의 : 브로큰 파이프 smpp.logica 라이브러리

20:43:40,798 ERROR Tx:809 - java.net.SocketException: Broken pipe 
java.net.SocketException: Broken pipe 
    at java.net.SocketOutputStream.socketWrite0(Native Method) 
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92) 
    at java.net.SocketOutputStream.write(SocketOutputStream.java:136) 
    at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65) 
    at java.io.BufferedOutputStream.write(BufferedOutputStream.java:109) 
    at com.logica.smpp.TCPIPConnection.send(TCPIPConnection.java:353) 
    at com.logica.smpp.Transmitter.send(Transmitter.java:79) 
    at com.logica.smpp.Session.send(Session.java:993) 
    at com.logica.smpp.Session.send(Session.java:1048) 
    at com.logica.smpp.Session.enquireLink(Session.java:789) 
    at com.logica.smpp.Tx.kirimEnquireLink(Tx.java:795) 
    at com.logica.smpp.Tx.access$0(Tx.java:777) 
    at com.logica.smpp.Tx$1.run(Tx.java:120) 
    at java.util.TimerThread.mainLoop(Timer.java:512) 
    at java.util.TimerThread.run(Timer.java:462) 

..I'm을 가지고 왜

하지만, 다음 오류가 난 문의 링크를 보내려고 out..when 올 ,, 내가 만든 세션이 syncronize이며 연결 유형은 여기 트랜시버이다 내가 바인딩 및 링크 enqury하는 데 사용되는 코드의 조각이다

private void bind() 
    { 
     debug.enter(this, "SMPPTest.bind()"); 
     try { 

      if (bound) { 
       System.out.println("Already bound, unbind first."); 
       return; 
      } 

      BindRequest request = null; 
      BindResponse response = null; 
      String syncMode = (asynchronous ? "a" : "s"); 

      // type of the session 
      syncMode = getParam("Asynchronous/Synchronnous Session? (a/s)", 
           syncMode); 
      if (syncMode.compareToIgnoreCase("a")==0) { 
       asynchronous = true; 
      } else if (syncMode.compareToIgnoreCase("s")==0) { 
       asynchronous = false; 
      } else { 
       System.out.println("Invalid mode async/sync, expected a or s, got " 
            + syncMode +". Operation canceled."); 
       return; 
      } 

      // input values 
      bindOption = getParam("Transmitter/Receiver/Transciever (t/r/tr)", 
            bindOption); 

      if (bindOption.compareToIgnoreCase("t")==0) { 
       request = new BindTransmitter(); 
      } else if (bindOption.compareToIgnoreCase("r")==0) { 
       request = new BindReceiver(); 
      } else if (bindOption.compareToIgnoreCase("tr")==0) { 
       request = new BindTransciever(); 
      } else { 
       System.out.println("Invalid bind mode, expected t, r or tr, got " + 
            bindOption + ". Operation canceled."); 
       return; 
      } 

      ipAddress = getParam("IP address of SMSC", ipAddress); 
      port = getParam("Port number", port); 

      TCPIPConnection connection = new TCPIPConnection(ipAddress, port); 
      connection.setReceiveTimeout(20*1000); 
      session = new Session(connection); 

      systemId = getParam("Your system ID", systemId); 
      password = getParam("Your password", password); 

      // set values 
      request.setSystemId(systemId); 
      request.setPassword(password); 
      request.setSystemType(systemType); 
      request.setInterfaceVersion((byte)0x34); 
      request.setAddressRange(addressRange); 

      // send the request 
      System.out.println("Bind request " + request.debugString()); 
      if (asynchronous) { 
       pduListener = new SMPPTestPDUEventListener(session); 
       response = session.bind(request,pduListener); 
      } else { 
       response = session.bind(request); 
      } 
      System.out.println("Bind response " + response.debugString()); 
      if (response.getCommandStatus() == Data.ESME_ROK) { 
       System.out.println("CommandID "+response.getCommandId()); 
       bound = true; 
      } 

     } catch (Exception e) { 
      event.write(e,""); 
      debug.write("Bind operation failed. " + e); 
      System.out.println("Bind operation failed. " + e); 
     } finally { 
      debug.exit(this); 
     } 
    } 

문의 링크 코드는

입니다.
private void kirimEnquireLink() 
    { 
    try 
    { 
     log.info("Send enquireLink!"); 
     EnquireLink request = new EnquireLink(); 
     EnquireLinkResp response = new EnquireLinkResp(); 
//  synchronized (session) { 
//  session.enquireLink(request); 
//  } 
     if(asynchronous) 
     { 
      session.enquireLink(request); 
     }else 
     { 
      response = session.enquireLink(request); 
      System.out.println("Enquire Link Response "+request.debugString()); 
     } 

    } 
    catch (Exception e) 
    { 
     bound = false; 
    // unbind(); 
     log.error(e, e); 
    } 
    } 

나는 어떤 생각 ,, 모든 십초 문의 링크를 불리는 이유

답변

1

당신이 직면하고있는 문제는 연결이 항상 사용할 수 있음을 보험이나 세션이 결코 없다는 것입니다. 다양한 외부 적 이유 때문에 ESME와 SMSC 간의 연결이 끊어 질 수 있습니다. 나의 제안은 enquire_link 작업과 제출 작업을 시도해보고 Exception을 평가하고 조치를 취하십시오. enquire_link와 동일한 작업을 수행

/** 
* Connect to ESME and submit a message, if binding process fails, reattempt 
* to reconnect and submit. 
*/ 
public void connect() { 

    try { 
     //Create connection 
     BindRequest request = null; 
     request = new BindTransciever(); 
     connection = new TCPIPConnection("localhost", 17632); 
     connection.setReceiveTimeout(20 * 1000); 
     session = new Session(connection); 
     //Prepare request 
     request.setSystemId("pavel"); 
     request.setPassword("wpsd"); 
     request.setSystemType("CMT"); 
     request.setInterfaceVersion((byte) 0x34); 
     request.setAddressRange(new AddressRange()); 
     pduListener = new SMPPTestPDUEventListener(session); 

     //Session binding process, if it fails, we are thrown to the catch section 
     //with a BrokenPipe (IOException) 
     session.bind(request, pduListener); 

     //Prepare message 
     SubmitSM msg = new SubmitSM(); 
     // set values 
     msg.setDestAddr("04234143939"); 
     msg.setShortMessage("hello"); 
     msg.assignSequenceNumber(true); 

     //Send to our custom made submitMessage method that reattempts if failure 
     submitMessage(msg); 

    } catch (Exception ex){ 
      //Analyze what type of exception was 
      if (ex instanceof IOException || ex instanceof SocketException){ 
       //IOException relate to the brokenpipe issue you are facing 
       //you need to close existing sessions and connections 
       //restablish session 
       if (this.connection!=null){ 
        this.connection.close(); 
       } 
       //This is a recursive call, I encourage you to elaborate 
       //a little bit this method implementing a counter so you 
       //don't end up in an infinite loop 
       this.connect(); 
      } else { 
       //LOG whatever other exception thrown 
      } 
    } 
} 

    /** 
* Submit message to SMSC, if it fails because of a connection issue, reattempt 
* @param message 
*/ 
private void submitMessage(SubmitSM message){ 
     try{ 
      session.submit(message); 
     } catch (Exception ex){ 
      //Analyze what type of exception was 
      if (ex instanceof IOException || ex instanceof SocketException){ 
       //IOException relate to the brokenpipe issue you are facing 
       //you need to close existing sessions and connections 
       //restablish session and try to submit again 
       if (this.connection!=null){ 
        this.connection.close(); 
       } 
       //Call a rebind method 
       this.bind(); 
       //This is a recursive call, I encourage you to elaborate 
       //a little bit this method implementing a counter so you 
       //don't end up in an infinite loop 
       this.submitMessage(message); 
      } else { 
       //LOG whatever other exception thrown 
      } 
     } 
} 

을 다음과 같이 내가 성공적으로 재귀 적 방법을 구현했습니다

이 문제를 처리하기 위해 호출 시도 - 캐치, IOException가 동안 바인딩하고 다시 시도합니다. 재귀 호출 중에 무한 루프를 피하기 위해 couter와 최대 시도 횟수를 추가하는 것을 잊지 마십시오.

10 초마다 enquire_link 할 필요가 없습니다. 대부분의 의료기관에서 얼마나 자주해야하는지 알려 드리며, 표준은 10 분입니다.

+0

감사의 말 ... 그 말이 맞는 이유는 ... 항상 예외가 생기는 이유입니다. 나는 말한대로 예외를 잡아서 다시 연결하려고합니다 ... 그럼 저는 문의 링크를 10 초 제공자가 요청했기 때문에 .. 언제나 감사합니다. – dmh

관련 문제