SMTP客户端响应超时

时间:2018-11-01 14:07:22

标签: java timeout smpp jsmpp

我的smpp客户端应用程序超时60000,但是服务器正常运行。 原因:org.jsmpp.extra.ResponseTimeoutException:60000毫秒后无响应

 public void connect() {
    final String ip = "localhost";
    final int port = 8056;
    final String message = "jSMPP simplify SMPP on Java platform";
    // set RegisteredDelivery
    final RegisteredDelivery registeredDelivery = new RegisteredDelivery();
    registeredDelivery.setSMSCDeliveryReceipt(SMSCDeliveryReceipt.SUCCESS_FAILURE);
    // bind(connect)
    final SMPPSession session = new SMPPSession();
    createSession(session, ip, port);
    session.addSessionStateListener((newState, oldState, source) -> {
        if (newState == SessionState.CLOSED) {
            /* throw away old session and create a new one */
            session.unbindAndClose();
            createSession(session, ip, port);
            try {
                String messageId = session.submitShortMessage("CMT", TypeOfNumber.INTERNATIONAL,
                        NumberingPlanIndicator.UNKNOWN, "1616", TypeOfNumber.INTERNATIONAL, NumberingPlanIndicator.UNKNOWN,
                        "", new ESMClass(), (byte) 0, (byte) 1, timeFormatter.format(new Date()), null,
                        registeredDelivery, (byte) 0, new GeneralDataCoding(Alphabet.ALPHA_DEFAULT, MessageClass.CLASS1,
                                false), (byte) 0, message.getBytes());
                System.out.println("Message submitted, message_id is " + messageId);
            } catch (PDUException | ResponseTimeoutException | InvalidResponseException | NegativeResponseException | IOException e) {
                e.printStackTrace();
            }
        }
    });

    // send Message
    try {

//字符串周期= convertStringToHex(“ 50000000”);             字符串messageId = session.submitShortMessage(“ CMT”,TypeOfNumber.INTERNATIONAL,                     NumberingPlanIndicator.UNKNOWN,“ 1616”,TypeOfNumber.INTERNATIONAL,NumberingPlanIndicator.UNKNOWN,                     “”,新的ESMClass(),(字节)0,(字节)1,timeFormatter.format(新的Date()),null,                     RegisteredDelivery,(字节)0,新的GeneralDataCoding(Alphabet.ALPHA_DEFAULT,MessageClass.CLASS1,                             false),(字节)0,message.getBytes());

        System.out.println("Message submitted, message_id is " + messageId);

    } catch (PDUException e) {
        // Invalid PDU parameter
        System.err.println("Invalid PDU parameter");
        e.printStackTrace();
    } catch (ResponseTimeoutException e) {
        // Response timeout
        System.err.println("Response timeout");
        e.printStackTrace();
    } catch (InvalidResponseException e) {
        // Invalid response
        System.err.println("Receive invalid respose");
        e.printStackTrace();
    } catch (NegativeResponseException e) {
        // Receiving negative response (non-zero command_status)
        System.err.println("Receive negative response");
        e.printStackTrace();
    } catch (IOException e) {
        System.err.println("IO error occur");
        e.printStackTrace();
    }

    // receive Message
    BasicConfigurator.configure();

    // Set listener to receive deliver_sm
    session.setMessageReceiverListener(new MessageReceiverListener() {

        public void onAcceptDeliverSm(DeliverSm deliverSm) {
            if (MessageType.SMSC_DEL_RECEIPT.containedIn(deliverSm.getEsmClass())) {
                // delivery receipt
                try {
                    DeliveryReceipt delReceipt = deliverSm.getShortMessageAsDeliveryReceipt();
                    long id = Long.parseLong(delReceipt.getId()) & 0xffffffff;
                    String messageId = Long.toString(id, 16).toUpperCase();
                    System.out.println("received '" + messageId + "' : " + delReceipt);
                    String msisdn = delReceipt.getText();
                    autoPaymentService.doBakcellAutopaymentsByMsisdn(msisdn);
                } catch (InvalidDeliveryReceiptException e) {
                    System.err.println("receive faild");
                    e.printStackTrace();
                }
            } else {
                // regular short message
                System.out.println("Receiving message : " + new String(deliverSm.getShortMessage()));
            }
        }

        public void onAcceptAlertNotification(AlertNotification alertNotification) {
            System.out.println("onAcceptAlertNotification");
        }

        public DataSmResult onAcceptDataSm(DataSm dataSm, Session source) {
            System.out.println("onAcceptDataSm");
            return null;
        }
    });
}

    public static void createSession(SMPPSession session, String ip, int port) {
    try {
        session.connectAndBind(ip, port, new BindParameter(BindType.BIND_TRX, "test", "test", "cp",
                TypeOfNumber.UNKNOWN, NumberingPlanIndicator.UNKNOWN, null));
        session.setTransactionTimer(100000L);
    } catch (IOException e) {
        System.err.println("Failed connect and bind to host");
        e.printStackTrace();
    }
}

0 个答案:

没有答案