【问题标题】:Problem with showing my packets in console with ACE使用 ACE 在控制台中显示我的数据包时出现问题
【发布时间】:2011-04-10 08:51:11
【问题描述】:

出于调试原因,我想在控制台中显示我的传出数据包。 顺便说一句,数据包正确到达服务器。 但是,如果我希望它们在发送前在控制台中显示,那么它什么也没有显示:

    ACE_Message_Block *m_Header;

    ...

    size_t send_len = m_Header->length(); // Size of the Message Block

    char* output = m_Header->rd_ptr();
    printf("Output: %s", output); // Trying to show it in Console
    // Send it
    server.send(m_Header->rd_ptr(), send_len);

有人有想法吗?

【问题讨论】:

    标签: c++ packet ace


    【解决方案1】:

    您发送的数据可能包含 0 - 您还需要附加换行符。

    for (size_t i = 0; i < send_len; ++i) {
      if (output[i]<32) {
        printf("\\x%02hhx", (unsigned char) output[i]);
      } else {
        printf("%c", output[i]);
      }
    }
    printf("\n");
    

    【讨论】:

    • 啊,谢谢,现在它向我显示:\x00\x06\x09\x00\x00\x00\x00\x1c 是否可以显示为十进制?
    • @Sapd:将第一个 printf 更改为例如printf("&lt;%hhi&gt;", output[i]);
    猜你喜欢
    • 2022-08-13
    • 2011-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-20
    • 2020-04-25
    • 1970-01-01
    相关资源
    最近更新 更多