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