[Interest] QNetworkAccessManager and HTTP persistent connection

Richard Moore rich at kde.org
Sat Nov 23 15:28:26 CET 2013


On 23 November 2013 13:45, iMath <2281570025 at qq.com> wrote:
> HTTP 1.1 supports persistent connection by default, so I want to send my a
> second http request using the same connection that was setup when the first
> HTTP request was made. how can this be achieved through Qt?
>
> If I simply make the second request after the first one finished like the
> following
>
> QNetworkAccessManager *manager = new QNetworkAccessManager(this);
> connect(manager, SIGNAL(finished(QNetworkReply*)),
>         this, SLOT(replyFinished(QNetworkReply*)));
>
> manager->get(QNetworkRequest(QUrl("http://qt-project.org")));
>
> it seems a new TCP connection to the server will be initiated (I have
> checked with a network sniffer) The experiment also says: If the reply is
> deleteLater() or abort() within finished() signal, the connection will be
> closed.

QNAM will use up to 6 concurrent connections and automatically reuse
them, use pipelining etc. as needed. We don't provide low level access
to the scheduler etc. that performs this. Note that in your code above
you create a second network access manager which totally breaks Qt's
ability to schedule things nicely for you or to reuse the connection.
Instead you should make a single QNAM and keep reusing it.

Regards

Rich.



More information about the Interest mailing list