Cloudhopper SMPP - 如何获取从其他客户端发送的消息内容?

时间:2014-02-20 11:28:57

标签: java smpp

我已从此链接下载github的源代码:https://github.com/twitter/cloudhopper-smpp

假设我想测试客户端之间的接收消息,所以我创建了一个服务器和2个客户端。为了运行服务器,我使用了命令“make server”。然后在其他机器中,客户端连接到我的服务器并使用以下代码向其他客户端发送1条消息,电话号码为“123456”

submit0.setSourceAddress(new Address((byte)0x03, (byte)0x00, "654321"));
submit0.setDestAddress(new Address((byte)0x01, (byte)0x01, "123456"));
submit0.setShortMessage(textBytes);

SubmitSmResp submitResp = session0.submit(submit0, 10000); 

电话号码为“123456”的客户如何从电话号码“654321”获取消息内容?

谢谢!

1 个答案:

答案 0 :(得分:3)

当您像这样创建sessionHandler时,

DefaultSmppSessionHandler sessionHandler = new ClientSmppSessionHandler();

此ClientSmppSessionHandler应扩展为DefaultSmppSessionHandler。 有2个听众。 请看下面的例子。

public class ClientSmppSessionHandler  extends DefaultSmppSessionHandler {

private static final Logger logger = LoggerFactory.getLogger(ClientSmppSessionHandler.class);

public ClientSmppSessionHandler() {
    super(logger);
}

@Override
public void firePduRequestExpired(PduRequest pduRequest) {
    logger.warn("PDU request expired: {}", pduRequest);
}

@Override
public PduResponse firePduRequestReceived(PduRequest pduRequest) {
    PduResponse response = pduRequest.createResponse();
     logger.info("SMS Received: {}", pduRequest);
     if (pduRequest.getCommandId() == SmppConstants.CMD_ID_DELIVER_SM) {
         DeliverSm mo = (DeliverSm) pduRequest;
         int length = mo.getShortMessageLength();
         Address source_address = mo.getSourceAddress();
         Address dest_address = mo.getDestAddress();
         byte[] shortMessage = mo.getShortMessage();
         String SMS= new String(shortMessage);
         logger.info(source_address + ", " + dest_address + ", " + SMS);
     }
     return response;
}

}