Reputation: 31
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?
Upvotes: 2
Views: 5135
Reputation: 2788
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.
Upvotes: 0
Reputation: 61
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
Upvotes: 0
Reputation: 6260
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.
Upvotes: 7