Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Problems with websockets



  • 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.



  • 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!



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



  • 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!


  • @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?


  • @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.



  • 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
    


  • @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.



  • 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!


Log in to reply