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. Problems with websockets
QtWS25 Last Chance

Problems with websockets

Scheduled Pinned Locked Moved Solved General and Desktop
websocket
8 Posts 3 Posters 2.8k 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.
  • S Offline
    S Offline
    SteMMo
    wrote on 2 Oct 2019, 07:34 last edited by
    #1

    Hi all,
    I'm developing a simple Qt app (5.7.1 Windows MinGW) to test a websockets connection to my running websocket server.
    I inserted websocket object both in C++ code and QML, pointing of course to same address ( url= 'ws://10.191.40.232:7681') .
    Both of them report the 'connected' status but I do not receive any notification on the server: if I send some text by socket.sendTextMessage() fn without errors.

    If I connect the server from a browser using Javascript new WebSocket(urlpath, protocol); where:
    URL: 'ws://10.191.40.232:7681/' - protocol: 'lws-minimal'
    everything is ok.
    'protocol' parameter is the only difference I see.
    Is there a way to specify the 'protocol' parameter on the QWebSocket constructor?

    If I point to 'ws://echo.websocket.org' site I receive the reply.

    Any idea?
    Regards.

    P 1 Reply Last reply 2 Oct 2019, 17:05
    0
    • S Offline
      S Offline
      SteMMo
      wrote on 8 Oct 2019, 15:35 last edited by
      #8

      I solved !
      The author of the libwebsockets library suggested me to initialize the engine with a default subprotocol if the client did not define it.
      And it worked !

      Thanks!

      1 Reply Last reply
      2
      • S SteMMo
        2 Oct 2019, 07:34

        Hi all,
        I'm developing a simple Qt app (5.7.1 Windows MinGW) to test a websockets connection to my running websocket server.
        I inserted websocket object both in C++ code and QML, pointing of course to same address ( url= 'ws://10.191.40.232:7681') .
        Both of them report the 'connected' status but I do not receive any notification on the server: if I send some text by socket.sendTextMessage() fn without errors.

        If I connect the server from a browser using Javascript new WebSocket(urlpath, protocol); where:
        URL: 'ws://10.191.40.232:7681/' - protocol: 'lws-minimal'
        everything is ok.
        'protocol' parameter is the only difference I see.
        Is there a way to specify the 'protocol' parameter on the QWebSocket constructor?

        If I point to 'ws://echo.websocket.org' site I receive the reply.

        Any idea?
        Regards.

        P Offline
        P Offline
        Pablo J. Rogina
        wrote on 2 Oct 2019, 17:05 last edited by
        #2

        @SteMMo is it possible that you capture the network traffic between your client(s) and the server? Wireshark is your friend here.

        Upvote the answer(s) that helped you solve the issue
        Use "Topic Tools" button to mark your post as Solved
        Add screenshots via postimage.org
        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        1
        • S Offline
          S Offline
          SteMMo
          wrote on 6 Oct 2019, 13:45 last edited by
          #3

          Yes, good idea.
          I copied and run the server on my local machine, I opened a console and run tcpdump on port 7681.

          sudo tcpdump tcp port 7681 -vvv
          

          In the application I changed the URL to "ws://localhost:7681".
          Then I added 4 buttons to the UI interface to open/close/write and get the state of the websocket object.
          Results:

          • Pressed 'open' and the onConnected slot reports 'connected!' debug string
          • Pressed 'getState' and it reports QAbstractSocket::ConnectedState
          • Pressed 'Send', the sendTextMessage fn are recalled but nothing else happened
          • Pressed 'close' and the onDisconnected slot report 'disconnected!' debug string
          • Pressed 'getState' and it reports QAbstractSocket::UnconnectedState
          • tcpdump reports NOTHING!
          P 1 Reply Last reply 7 Oct 2019, 12:54
          0
          • S SteMMo
            6 Oct 2019, 13:45

            Yes, good idea.
            I copied and run the server on my local machine, I opened a console and run tcpdump on port 7681.

            sudo tcpdump tcp port 7681 -vvv
            

            In the application I changed the URL to "ws://localhost:7681".
            Then I added 4 buttons to the UI interface to open/close/write and get the state of the websocket object.
            Results:

            • Pressed 'open' and the onConnected slot reports 'connected!' debug string
            • Pressed 'getState' and it reports QAbstractSocket::ConnectedState
            • Pressed 'Send', the sendTextMessage fn are recalled but nothing else happened
            • Pressed 'close' and the onDisconnected slot report 'disconnected!' debug string
            • Pressed 'getState' and it reports QAbstractSocket::UnconnectedState
            • tcpdump reports NOTHING!
            P Offline
            P Offline
            Pablo J. Rogina
            wrote on 7 Oct 2019, 12:54 last edited by
            #4

            @SteMMo so you're saying that you cannot capture any message...
            2 things please:

            1. could you try with another different client app connecting to the same local server, and capture traffic? To rule out that you're indeed able to capture traffic
            2. could you show some of your code?

            Upvote the answer(s) that helped you solve the issue
            Use "Topic Tools" button to mark your post as Solved
            Add screenshots via postimage.org
            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            2
            • S Offline
              S Offline
              SteMMo
              wrote on 8 Oct 2019, 13:26 last edited by
              #5

              @Pablo-J-Rogina Now I installed Wireshark to sniff on the client side.
              Filtering by port number I finally see some data:
              i see the GET request and reply with the 'switching protocol'.
              The server does not fire the ESTABLISHED phase.
              I wrote to the libwebsockets library author to clean the problem.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SteMMo
                wrote on 8 Oct 2019, 14:34 last edited by
                #6

                The author reply me pointing to the subprotocol definition.
                But the actual implementation doesn't support the subprotocol, is it?
                https://doc.qt.io/qt-5/qwebsocket.html
                The request is:

                GET / HTTP/1.1
                Host: 10.191.40.232:7681
                Upgrade: websocket
                Connection: Upgrade
                Sec-WebSocket-Key: BHWCOoFRwagELAIWRB2iDg==
                Sec-WebSocket-Version: 13
                
                1 Reply Last reply
                0
                • fcarneyF Offline
                  fcarneyF Offline
                  fcarney
                  wrote on 8 Oct 2019, 15:06 last edited by fcarney 10 Aug 2019, 15:06
                  #7

                  @SteMMo
                  Interesting, that page you linked says this:
                  "QWebSocket currently does not support WebSocket Extensions and WebSocket Subprotocols."

                  I will have to keep this in mind. We use websockets a lot.

                  C++ is a perfectly valid school of magic.

                  1 Reply Last reply
                  1
                  • S Offline
                    S Offline
                    SteMMo
                    wrote on 8 Oct 2019, 15:35 last edited by
                    #8

                    I solved !
                    The author of the libwebsockets library suggested me to initialize the engine with a default subprotocol if the client did not define it.
                    And it worked !

                    Thanks!

                    1 Reply Last reply
                    2

                    1/8

                    2 Oct 2019, 07:34

                    • Login

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