简体   繁体   中英

Normal HTTP request vs TCP connection + HTTP header

I'm trying to emulate http request using TCP connection + HTTP header. I test it using VLC player. I use QT to develop my app.

So, basically I start streaming video in VLC player to host http://192.168.0.100:55555 . Then in code I try to connect to the server via http GET request, which succeeds.

I would like instead of http request to connect by TCP to http://192.168.0.100:55555 and send plain GET request as a text using the same socket, but I get QAbstractSocket::ConnectionRefusedError .

QTcpSocket* socket = new QTcpSocket();
socket->connectToHost(m_session->remoteHost().address, m_session->remoteHost().port);
// Then I get QAbstractSocket::ConnectionRefusedError in a slot
// connected to error() signal

I wonder if it is possible to do so and if you have any suggestions.

Thank you

Why not base your code from the Http download example ?

//...
    reply = qnam.get(QNetworkRequest(url));
//...
    connect(reply, SIGNAL(readyRead()),
        this, SLOT(httpReadyRead()));
//....
void HttpWindow::httpReadyRead()
{
    // this slot gets called every time the QNetworkReply has new data.
    // We read all of its new data and write it into the file.
    // That way we use less RAM than when reading it at the finished()
    // signal of the QNetworkReply
    if (file)
        file->write(reply->readAll());
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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