首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用jsmpp的smpp服务器的绑定问题

使用jsmpp的smpp服务器的绑定问题
EN

Stack Overflow用户
提问于 2016-06-09 21:05:31
回答 1查看 1.6K关注 0票数 0

我有一个java应用程序,它使用jsmpp库发送短信到短信服务中心。应用程序连接成功并发送短消息。连接问题发生在一周左右的运行时间后,在此运行时间内,它会发送数千条SMS。但几天后,应用程序突然开始面临连接问题,有时是“负面绑定响应0x00045”,有时是等待绑定响应。当我从wireshark检查时,应用程序不断地发送查询线路数据包,并接收状态为“OK”的响应。这意味着应用程序已连接,但它仍在尝试新的连接。下面是连接管理的代码。

我调用newSession方法来获取发送短信的会话..

代码语言:javascript
复制
 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);
            }
        }
    }

我不明白为什么这段代码会在已经连接的时候重试新的连接。任何线索都很感谢。

EN

回答 1

Stack Overflow用户

发布于 2016-06-13 16:09:19

看起来会话仍然有效。确保没有僵尸会话,如果有则将其全部关闭。确保查询链接的发送停止。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37726850

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档