gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 05:28:31 25 4
gpt4 key购买 nike

我已经通过这个链接从 github 下载了源代码:https://github.com/twitter/cloudhopper-smpp

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

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”的消息内容?

谢谢!

最佳答案

当您像这样创建 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;
}

关于java - Cloudhopper SMPP - 如何获取从其他客户端发送的消息内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21906412/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com