简体   繁体   English

如何使Qt Websocket和QNetworkRequest(HTTP)使用相同的连接?

[英]How to make Qt Websocket and QNetworkRequest (HTTP) to use the same connection?

Is it possible with Qt to upgrade a HTTP connection that handles the normal HTTP requests to a Websocket with the same connection? Qt是否可以将处理正常HTTP请求的HTTP连接升级到具有相同连接的Websocket?

I'm thinking about something like this with Poco libraries, but all done in Qt similar to QtWebApp . 我在考虑像这样与波科库,但所有Qt中做类似QtWebApp

The simple answer is no and that is mostly because of specifics of the server side. 简单的答案是“否”,这主要是因为服务器端的具体情况。 And Qt just follows the protocol available and exposed by the server (HTTP/WebSocket) as mostly the client-side development framework and AFAIK won't be able to do the kind of transformation you want of going from HTTP to Websocket that are two different protocols. 而且Qt只是遵循服务器提供的可用协议(HTTP / WebSocket),因为大多数客户端开发框架和AFAIK将无法完成您想要的从HTTP到Websocket的两种转换。协议。 But of course, theoretically that can be done as long as both protocols able to use IP port 80. But that implies new unique sever and new unique client implementations. 但是,当然,从理论上讲,只要两个协议都能够使用IP端口80,就可以做到。但这意味着新的唯一服务器和新的唯一客户端实现。

We use both WebSocket and REST in our app. 我们在应用程序中同时使用WebSocket和REST。 And WebSocket is for triggering the client by the server to do something. WebSocket用于由服务器触发客户端以执行某些操作。 Client gets the "poke" from the server and starts normal JSON HTTP-based exchange with the server. 客户端从服务器获取“戳”,并开始与服务器进行基于JSON HTTP的常规交换。

Somewhat relative link: https://softwareengineering.stackexchange.com/questions/276253/mixing-rest-and-websocket-in-the-same-api 相对链接: https : //softwareengineering.stackexchange.com/questions/276253/mixing-rest-and-websocket-in-the-same-api

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM