如何在 Qt5 中通过 http 连接到 PUSH 服务器

Posted

技术标签:

【中文标题】如何在 Qt5 中通过 http 连接到 PUSH 服务器【英文标题】:How to connect to a PUSH server via http in Qt5 【发布时间】:2014-06-03 17:23:56 【问题描述】:

查看 QNetworkAccessManager 我没有看到任何与“推送”相关的内容。 http://qt-project.org/doc/qt-5/qnetworkaccessmanager-members.html 与 POST 或 GET 不同,使用“推送”http 连接,您正在维护连接,以便您可以接收来自服务器的定期更新。 Qt5 中用于 HTTP REST“推送”客户端连接的正确功能是什么?或者可能是持久的 http 连接?

【问题讨论】:

有没有一个叫做 PUSH 的 HTTP 动词? @Sleiman Jneidi en.wikipedia.org/wiki/Push_technology 通过 REST API。基本上是一个持久连接 GET。 那是动词吗? en.wikipedia.org/wiki/… 与GET请求相同,但http会话永远不会结束。 【参考方案1】:
> How would I use QNetworkAccessManager to connect to an http push server?
<thiago> pEYEd: what HTTP command do you need to send?
> thiago good point. I am not sure. It looks like json  https://www.cryptsy.com/pages/pushapi
<thiago> pEYEd: JSON is not an HTTP command
<thiago> try again: what HTTP command do you need to send?
> i know
<thiago> pEYEd: let me try this: have you tried to simply get() the page?
> it looks like POST
> http://pusher.com/docs/client_api_guide/client_connect
<thiago> then use post()
> thiago will it automatically do a persistant connection?
<thiago> pEYEd: what exactly do you need to happen?
<thiago> it will keep giving you data as long as there's data to be given
> but it can't time out
<thiago> once the data ends, the connection may be closed or reused. But you cannot and must not care about it.
<thiago> there's no timeout mechanism in QNAM
> no FIN/ACK unless specified?
<thiago> that's at a much lower level
<thiago> the HTTP request/reply ends when the server says it ends
> the connection can't close. no fin/ack
<thiago> under HTTP/1.1, it ends when the number of bytes specified in Content-Length is reached
<thiago> or the chunked encoding says it's the last chunk
<thiago> if either of those conditions happen, the QNetworkReply signals the end
<thiago> then QNAM can do whatever it wants to the socket
> Thank you!

【讨论】:

以上是关于如何在 Qt5 中通过 http 连接到 PUSH 服务器的主要内容,如果未能解决你的问题,请参考以下文章

我们可以在 react native 中通过蓝牙连接到热敏收据打印机吗

在 Java 中通过 SSH 隧道连接到 Mongo 数据库

在 Omnet++ 中通过 AP 将无线主机连接到标准主机

在Java中通过IP连接到服务器时出现ConnectException

在 Android 中通过 XAMPP 连接到 MYSQL

在 PHP 中通过 SSH 连接到 MySQL