🎄 Happy Holidays! 🥳

Most of Solace is closed December 24–January 1 so our employees can spend time with their families. We will re-open Thursday, January 2, 2024. Please expect slower response times during this period and open a support ticket for anything needing immediate assistance.

Happy Holidays!

Please note: most of Solace is closed December 25–January 2, and will re-open Tuesday, January 3, 2023.

GARBAGE CHARACTER getting added in messages received in Request/Reply messaging method.

TestSolace
TestSolace Member Posts: 16

Hi Team,
I am using request and reply mechanism to send and receive messages. After I have sent the message, in the receiving Callback method i found that a garbage character is getting added at the end of the message. So on receiving the message, i am getting the garbage character,
Following is the way i am sending message:
std::string text_p = "ABCD";
solClient_uint32_t dataLen1 = ( solClient_uint32_t )strlen( (text_p.c_str()) );
solClient_opaqueMsg_pt replyMsg_p;
solClient_msg_alloc(&replyMsg_p);
solClient_opaqueMsg_pt msg_p = NULL;
solClient_msg_alloc ( &msg_p ) ;
solClient_msg_setDestination ( msg_p, &destination, sizeof ( destination ))
solClient_msg_setBinaryAttachment ( msg_p, text_p.c_str(), (dataLen1));
solClient_session_sendRequest ( session_p, msg_p, &replyMsg_p, timeout);

I am using C Api.
Can anyone please tell me what is adding the garbage character and how to fix it.
Thanks.

Comments

  • TomF
    TomF Member, Employee Posts: 412 Solace Employee

    Hi @TestSolace, can I check the message flow here?
    The above code sends a request/reply message, using the above code to a responding application.
    Is the extra character received by the responding application?
    Or does the responding application simply "bounce" the request back as a reply?
    Could you add the code for the responding application? How are you displaying the message data, via solClient_msg_dump()?

  • Ragnar
    Ragnar Member, Employee Posts: 67 Solace Employee

    You have not posted the code that is seeing the 'extra' character so this is speculation. The publisher you have posted sends 4 bytes of payload as strlen does not include the null termination of a string. Any code that retrieves the payload will get 4 bytes of binary payload that happen to look like a string but is not a string as it is not null terminated. If you attempt to retrieve the payload and print it, it is quite likely that you will see garbage characters at the end, or crash.

  • TestSolace
    TestSolace Member Posts: 16

    Hi @Aaron ,
    It is a random garbage.
    Yes, i have followed all the Links as you hav mentioned.
    Thanks.

  • TestSolace
    TestSolace Member Posts: 16

    Hi @TomF
    The functionality is such that, it has to get back the same message which it has sent.
    So I am creating a reply in the Call back function using the message i have sent.
    After that i am sending the constructed reply. I am showing the message using printf function.
    Thanks.

  • TomF
    TomF Member, Employee Posts: 412 Solace Employee

    @TestSolace I think fixing the string null termination issue, as @Ragnar suggests, is the first thing to do.

  • TestSolace
    TestSolace Member Posts: 16

    Hi @TomF ,
    Yes, @Ragnar suggestion helped me to fix the issue.
    Thanks.