Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for WebAssembly
  4. The WebSocket connection to the MQTT server stops working after placing the application on the GitHub server.
QtWS25 Last Chance

The WebSocket connection to the MQTT server stops working after placing the application on the GitHub server.

Scheduled Pinned Locked Moved Unsolved Qt for WebAssembly
5 Posts 4 Posters 851 Views
  • 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.
  • E Offline
    E Offline
    Espoo
    wrote on 24 Jan 2023, 10:52 last edited by
    #1

    I am trying to run the WebSockets MQTT Subscription Example under WebAssembly, which I found here: https://doc.qt.io/qt-6/qtmqtt-websocketsubscription-example.html. To do this, I downloaded the Qt MQTT module, compiled it and ran the example. Generally, everything works fine on my computer, both if the project is run as a desktop and as a web assembly under the browser, I can see in the browser logs that the application connects to the MQTT server and receives messages. The problem occurred when I uploaded the project to the server at https://rafal-tarnow.github.io/websocketsubscription.html. In the browser logs, I see that the project is loaded and trying to connect to the MQTT server and at this moment nothing else happens. What might be the cause that if I run the project locally in the browser it can connect to the MQTT server but if the project is running from the GitHub server it does not work? I slightly modified the main file:

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);
    QCoreApplication::setApplicationVersion("1.0");

    QString topic = "testOutTopic";
    
    ClientSubscription clientsub;
    clientsub.setUrl(QUrl("ws://broker.hivemq.com:8000/mqtt"));
    clientsub.setTopic(topic);
    
    //clientsub.setVersion(4);
    clientsub.setVersion(3);
    
    clientsub.connectAndSubscribe();
    
    qDebug() << "Topic = " << topic;
    return a.exec();
    

    }

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 24 Jan 2023, 19:58 last edited by
      #2

      Hi,

      Did you check that GitHub allows connection to server on arbitrary ports ?

      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
      0
      • E Offline
        E Offline
        Espoo
        wrote on 25 Jan 2023, 07:31 last edited by
        #3

        I found one problem, when app is downloaded to browser via https protocol, browser don't allow use non encrypted WebSockets, but this problem can be omitted by changing browser security policy (for Firefox go to about:config site and set network.websocket.allowInsecureFromHTTPS to true). But the problem still occur. I don't thing that is GitHub allows connection to server on arbitrary ports problem, because application is downloaded to browser and connection to mqtt server is called form there, not form GitHub, but I check that.

        1 Reply Last reply
        0
        • E Espoo referenced this topic on 9 Feb 2023, 07:36
        • M Offline
          M Offline
          Marcin22
          wrote on 3 Apr 2023, 13:45 last edited by
          #4

          Any luck with the issue? I have a similar problem, when serving my Qt WASM application over HTTPS. I have not secured WebSockets in my app (as SSL seems not to work for Qt WASM) and everything works perfectly fine as long as I serve it over HTTP. When I only change it to HTTPS, even with the browser config appropriately set to handle such cases, no messages are sent from the Qt app.

          1 Reply Last reply
          0
          • E Offline
            E Offline
            Erni42 0
            wrote on 20 Aug 2024, 20:28 last edited by
            #5

            found one point in firefox, you have to accept a self signed certificate for the 443 port (https) and for the port of your websocket request (may be 1234).
            call your adress https://192.168.1.1 to load the wasm app and then call https:192.168.1.1:1234 for your connection to the websocket server and accept the certificate

            1 Reply Last reply
            0

            • Login

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