Search code examples
c++qtwebsocketstomp

Sending a STOMP frame through websocket


Since there's no webstomp (STOMP through Websocket) C++ implementation anywhere, I'm developing my own. I have a webstomp server set up already, and I've confirmed that it works using the javascript implementation of webstomp.

Now I'm relying on QT's implementation of websocket. I tested and works with a regular websocket. So now comes the implementation of STOMP. Looking at the STOMP frames the first frame I have to send could be something like this:

CONNECT
login: <username>
passcode: <passcode>

^@

With ^@being the null-character. The problem I'm having is that no matter what I do, I can't seem to get any type of response from the server. I tried different encodings, different messages, different connect frames, etc. I was wondering if I was doing something wrong or if I was missing something. An example of the above frame looks like this:

void WebSTOMP::onConnected()
{
    if (m_debug)
        qDebug() << "WebSocket connected";
    connect(&m_webSocket, &QWebSocket::textMessageReceived,
            this, &EchoClient::onTextMessageReceived);
    std::string myMessage = "CONNECT \nlogin: test\npasscode : test\n\n\0";

    m_webSocket.sendTextMessage(QString::fromUtf8(myMessage.c_str()));
}

And then I never get a response back.

Thanks in advance =)


Solution

  • Add one to the length of the message due to the string's null character terminator