Cloudhopper SMPP - 如何将MO短信发送给客户端?

时间:2014-09-02 15:23:43

标签: java smpp

来自https://github.com/twitter/cloudhopper-smpp/blob/master/src/test/java/com/cloudhopper/smpp/demo/ServerMain.java的演示提供了从客户端接收MT消息的示例。但是如何从服务器向连接的客户端发送消息(deliver_sm)?

1 个答案:

答案 0 :(得分:1)

我刚从ClientMain获取代码并将SubmitSm更改为DeliverSm。 出于测试目的,我从Console读取msg文本并使用此代码发送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) {}
}