Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt6 QWebSocket - how to send message to a different endpoint?
Forum Updated to NodeBB v4.3 + New Features

Qt6 QWebSocket - how to send message to a different endpoint?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 451 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    D_V_G
    wrote on last edited by
    #1

    I am trying to implement a client application for a third-party WebSockets server which uses the STOMP protocol. I got to the point where I get a "CONNECTED" (i.e., successful) response from the server. Now I need to start sending messages, starting from the custom authentication frame/message, and then the normal payload.

    The problem is: the QWebSocket's current URL is

    wss://thirdpartydomain.com/cache/stream/connect

    but I need to send the next message to a different endpoint (on the same host and port):

    wss://thirdpartydomain.com/cache/stream/message

    How can I redirect the QWebSocket to a different URL path?

    I tried the following, but the URL does not seem to change:

    QString m_stream_base_url = "wss://thirdpartydomain.com/cache/stream";
    ...
    QString connect_url = m_stream_base_url + "/connect";
    ... 
    *[here, the socket is opened and successfully negotiates the CONNECT flow]*
    ...
    QString message_url = m_stream_base_url + "/message";
    QNetworkRequest auth_request(QUrl(message_url));
    m_webSocket.request() = auth_request;
    qDebug() << "Updated web socket:" << m_webSocket.request().url();
    

    How can I change the target endpoint of an already-open QWebSocket?

    D 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #3

      Hi,

      To the best of my knowledge, you can't.

      It seems you would either need two sockets or to open a new connection once the original exchange is done.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • D D_V_G

        I am trying to implement a client application for a third-party WebSockets server which uses the STOMP protocol. I got to the point where I get a "CONNECTED" (i.e., successful) response from the server. Now I need to start sending messages, starting from the custom authentication frame/message, and then the normal payload.

        The problem is: the QWebSocket's current URL is

        wss://thirdpartydomain.com/cache/stream/connect

        but I need to send the next message to a different endpoint (on the same host and port):

        wss://thirdpartydomain.com/cache/stream/message

        How can I redirect the QWebSocket to a different URL path?

        I tried the following, but the URL does not seem to change:

        QString m_stream_base_url = "wss://thirdpartydomain.com/cache/stream";
        ...
        QString connect_url = m_stream_base_url + "/connect";
        ... 
        *[here, the socket is opened and successfully negotiates the CONNECT flow]*
        ...
        QString message_url = m_stream_base_url + "/message";
        QNetworkRequest auth_request(QUrl(message_url));
        m_webSocket.request() = auth_request;
        qDebug() << "Updated web socket:" << m_webSocket.request().url();
        

        How can I change the target endpoint of an already-open QWebSocket?

        D Offline
        D Offline
        D_V_G
        wrote on last edited by D_V_G
        #2

        @D_V_G
        Since the request() is const, I also - just in case - tried to do the following, which also does not work for the same reason:

        QUrl message_endpoint_url = QUrl(m_stream_base_url + "/message");
        m_webSocket.request().setUrl(message_endpoint_url);
        

        I dug into the Qt 6.6.1 code for QWebSocket and QWebSocketPrivate classes
        It looks like there is no way to change the URL path dynamically, short of modifying the source code or creating custom classes.
        Am I missing a better solution?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #3

          Hi,

          To the best of my knowledge, you can't.

          It seems you would either need two sockets or to open a new connection once the original exchange is done.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • D D_V_G has marked this topic as solved on

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved