Why smppcxx sample_app isn't working and returns "SMPP error: Invalid command_length" and crashes?

Why smppcxx sample_app isn't working and returns "SMPP error: Invalid command_length" and crashes?

我从 smppcxx 库中取出 sample_app 并将设置更改为:

const std::string ipaddr = "194.228.174.1";
const Smpp::Uint16 port = 9111;
const Smpp::SystemId sysid("MaxiTipSMPP");
const Smpp::Password pass(<actual_password>);
const Smpp::SystemType systype("");
const Smpp::Uint8 infver = 0x34;
const Smpp::ServiceType servtype("");
const Smpp::Address srcaddr("234567");
const Smpp::Address dstaddr("420606752839");
const std::string msgtext = "Hello smsc";

调用的代码是:

    Socket sd;
    sd.connect(ipaddr.c_str(), port);
    send_bind(sd);
    read_bind_resp(sd);
    //send_enquire_link(sd);
    //read_enquire_link_resp(sd);
    send_submit_sm(sd);
    read_submit_sm_resp(sd);
    Smpp::Uint32 seqnum = read_deliver_sm(sd);
    send_deliver_sm_resp(sd, seqnum);
    //send_data_sm(sd);
    //read_data_sm_resp(sd);
    //seqnum = read_deliver_sm(sd);
    //send_deliver_sm_resp(sd, seqnum);
    send_unbind(sd);
    read_unbind_resp(sd);

问题发生在 read_submit_sm_resp(sd)(如果未注释,则发生在 read_enquire_link_resp(sd)):

    Buffer buf;
    buf = read_smpp_pdu(sd, buf);
    std::cout << "\nRead a submit sm resp\n";
    Smpp::hex_dump(&buf[0], buf.size(), std::cout);
    Smpp::SubmitSmResp pdu;
    std::cout << "read_submit_sm_resp buf.size() is " << buf.size() << std::endl;
    pdu.decode(&buf[0]);
    std::string sid = pdu.message_id();
    printf("response message_id: \"%s\"\n", sid.c_str());

在线

    pdu.decode(&buf[0]);

,为什么?应用程序崩溃。我希望代码能按原样工作,但事实并非如此。

有输出:

Sending a bind transceiver
00 00 00 2a 00 00 00 09 00 00 00 00 00 00 00 01    ...*............
4d 61 78 69 54 69 70 53 4d 50 50 00                MaxiTipSMPP.password

Read a bind response
00 00 00 15 80 00 00 09 00 00 00 00 00 00 00 01    ................
53 4d 53 43 00                                     SMSC.
read_bind_resp buf.size() is 21
response system_id: "SMSC"

Sending a submit sm
00 00 00 3d 00 00 00 04 00 00 00 00 00 00 00 01    ...=............
00 00 00 32 33 34 35 36 37 00 01 01 34 32 30 36    ...234567...4206
30 36 37 35 32 38 33 39 00 00 00 00 00 00 01 00    06752839........
00 00 0a 48 65 6c 6c 6f 20 73 6d 73 63             ...Hello smsc

Read a submit sm resp
00 00 00 a4 00 00 00 05 00 00 00 00 00 00 00 01    ................
00 01 01 39 39 39 30 33 30 00 01 01 34 32 30 36    ...999030...4206
30 36 37 35 32 38 33 39 00 04 00 00 00 00 00 00    06752839........
00 00 47 69 64 3a 66 62 32 37 37 66 62 34 33 66    ..Gid:fb277fb43f
63 31 34 36 66 30 39 61 39 31 37 37 32 63 37 63    c146f09a91772c7c
31 33 64 65 35 62 20 64 6f 6e 65 20 64 61 74 65    13de5b done date
3a 31 37 30 32 30 36 30 35 30 37 30 34 20 73 74    :170206050704 st
61 74 3a 55 4e 44 45 4c 49 56 00 1e 00 21 66 62    at:UNDELIV...!fb
32 37 37 66 62 34 33 66 63 31 34 36 66 30 39 61    277fb43fc146f09a
39 31 37 37 32 63 37 63 31 33 64 65 35 62 00 04    91772c7c13de5b..
27 00 01 05                                        '...
read_submit_sm_resp buf.size() is 164
SMPP error: Invalid command_length

我添加了一个输出,它告诉我大小是 164,我看到 164 个字节,在绑定响应中,这没有问题,大小是 21,我看到 21 个字节,我应该以某种方式修复解码功能吗?

Smpp::SubmitSmResp::decode(const Smpp::Uint8* buff)
{
    Response::decode(buff);

    Smpp::Uint32 len = Response::command_length();
    Smpp::Uint32 offset = 16;
    const char* err = "Bad length in submit_sm_resp";
    if(len < offset)
        throw Error(err);

    const Smpp::Char* sptr = reinterpret_cast<const Smpp::Char*>(buff);
    message_id_ = &sptr[offset];
    offset += message_id_.length() + 1;

    if(len < offset)
        throw Error(err);

    Header::decode_tlvs(buff + offset, len - offset);
}

我仍然认为库应该按原样工作,所以我想也许我应该更改一些设置或其他内容。有人有同样的问题吗?知道该怎么办吗?我唯一想要的就是发短信,一天最多100条...

我设法修复了它。

1) 只有 1 个打开的连接,而不是为每个要发送的短信打开一个新连接。供应商禁止我,因为连接开口太多。

2) 流程不是发送->读取->发送->读取->..,但响应的读取应该异步完成,因此客户端必须解析响应以了解什么类型收到回复。

3) 应与 send_enquire_link 保持连接。

我猜想,对于像我这样对 smpp 一无所知的人来说,编写此网关以发送短信的时间远远超过 1 个工作日的范围。我在大约 3 天内完成了任务,一夜之间完成了大量工作。我为什么要添加那个?因为主要问题是我的方法,因为分配的时间 => 我认为应该有一个简单的解决方案来解决 1 manday 任务...