2

I have created a QTcpServer on port 1024. I want to connect to it from a websocket by using the URL ws://localhost:1024, but it is not getting connected. Can't we connect websockets to regular TCP server sockets?

stakx - no longer contributing
  • 83,039
  • 20
  • 168
  • 268
user1608693
  • 31
  • 1
  • 2

3 Answers3

7

Websockets aren't pure TCP sockets. Under the hood they use a custom protocol that is built on top HTTP. So the layering looks like this: IP > TCP > HTTP > WebSocket.

Therefore to provide a websocket server in Qt you need websocket protocol implementation. Check out QtWebsocket for that implementation.

Ihor Kaharlichenko
  • 5,944
  • 1
  • 26
  • 32
0

As Ihor indicated, a WebSocket starts with an HTTP request, which is then upgraded to a WebSocket. You can have a look at QtWebSockets. It is part of the Qt playground, and can be used both for client and server implementations.

Kurt Pattyn
  • 2,758
  • 2
  • 30
  • 42
0

Slightly disengenuous information. They are NOT "built upon" HTTP, WebSocket's are much closer to the TCP layer. However they require the upgrade server handshake via an HTTP request.

link to the RFC - https://www.rfc-editor.org/rfc/rfc6455#section-1.7

Community
  • 1
  • 1
Erik
  • 61
  • 4