Cloudhopper SMPP - How to send MO sms to client?

爷,独闯天下 提交于 2019-12-13 07:35:31

问题


Demo from https://github.com/twitter/cloudhopper-smpp/blob/master/src/test/java/com/cloudhopper/smpp/demo/ServerMain.java provides an example of receiving MT messages from client. But how to send messages (deliver_sm) from server to connected client?


回答1:


I just took code from ClientMain and changed SubmitSm to DeliverSm. For testing purpose I read msg text from Console and send Message using this code. You should call this method in separate thread. Also you should handle list of sessions so you can get session reference when you want to send message.

void sendMessage( SmppSession session,  String message) {

    try {
        byte[] textBytes = CharsetUtil.encode(message, CharsetUtil.CHARSET_UCS_2);

        DeliverSm deliver = new DeliverSm();

        deliver.setSourceAddress(new Address((byte)0x03, (byte)0x00, "40404"));
        deliver.setDestAddress(new Address((byte)0x01, (byte)0x01, "44555519205"));
        deliver.setShortMessage(textBytes);

        WindowFuture<Integer,PduRequest,PduResponse> future = session.sendRequestPdu(deliver, 10000, false);
        if (!future.await()) {
            logger.error("Failed to receive deliver_sm_resp within specified time");
        } else if (future.isSuccess()) {
            DeliverSmResp deliverSmResp = (DeliverSmResp)future0.getResponse();
            logger.info("deliver_sm_resp: commandStatus [" + deliverSmResp.getCommandStatus() + "=" + deliverSmResp.getResultMessage() + "]");
        } else {
            logger.error("Failed to properly receive deliver_sm_resp: " + future.getCause());
        }
    } catch (Exception e) {}
}


来源:https://stackoverflow.com/questions/25626983/cloudhopper-smpp-how-to-send-mo-sms-to-client

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!