QHttpServer, where is it?
-
@SPlatten said in QHttpServer, where is it?:
I've implemented QTcpServer in my application and this "worked" fine, I want to modify it so the response is managed by a thread as its quite possible to get multiple requests simultaneously and I don't want the application to wait around dealing with requests individually.
There's the Threaded Fortune Server Example
Should get you started 😉
-
google is your friend: https://github.com/qt-labs/qthttpserver
-
@SPlatten said in QHttpServer, where is it?:
QHttpServer,
If you refer to this QHttpServer it seems deprecated.
You may want to look at new Qt Http Server provided as module from Qt, see this post. Be aware of the GPL license just in case.
-
@Christian-Ehrlicher , to be honest its not really what I want anyway, I'm just looking for some good tutorials on how to use QTcpServer and QTcpSocket.
-
@SPlatten said in QHttpServer, where is it?:
looking for some good tutorials on how to use QTcpServer and QTcpSocket.
So why don't you use that sentence as the title of your post?
-
@SPlatten said in QHttpServer, where is it?:
how to use QTcpServer and QTcpSocket.
Now QTcpServer ? Please clarify what you really want...
For QTcpServer the documentation has some examples. -
I've implemented QTcpServer in my application and this "worked" fine, I want to modify it so the response is managed by a thread as its quite possible to get multiple requests simultaneously and I don't want the application to wait around dealing with requests individually.
void clsSocketServer::readClient() { enum { REQ_METHOD = 0 ,REQ_DATA }; QTcpSocket* pSckClient = (QTcpSocket*)sender(); if (!pSckClient->canReadLine() ) { return; } QStringList slstTokens = QString(pSckClient->readLine()).split(QRegExp("[ \r\n][ \r\n]*")); if ( slstTokens[REQ_METHOD] != "GET" ) { return; } QString strRequest = slstTokens[REQ_DATA]; int intIdx = strRequest.indexOf(clsJSON::msccOpenCurlyBracket); if ( intIdx >= 0 && strRequest[strRequest.length() - 1] == clsJSON::msccCloseCurlyBracket ) { //Skip to start of JSON strRequest = strRequest.mid(intIdx); //Translate request, converting escaped characters strRequest = QUrl::fromPercentEncoding(strRequest.toLatin1()); //Create JSON object clsJSON objJSON(&strRequest); if ( objJSON.blnIsValid() == true ) { //Set-up response stream QTextStream tsResponse(pSckClient); tsResponse.setAutoDetectUnicode(true); //Create thread to deal with request and send response std::thread* pthdCliHelper = new std::thread(clsSocketServer::manageRequest ,&objJSON, &tsResponse); if ( pthdCliHelper != nullptr ) { pthdCliHelper->join(); } } } /*NOTE: Do not close connection, once established connections between modules and server * stay open until the server dies! pSckClient->close(); if (pSckClient->state() == QTcpSocket::UnconnectedState) { delete pSckClient; }*/ }
I can see that the request is being received and the "manageRequest" is dealing the response, however this doesn't make it to the client...I'm using a web-browser as the client to test.
-
@SPlatten said in QHttpServer, where is it?:
I've implemented QTcpServer in my application and this "worked" fine, I want to modify it so the response is managed by a thread as its quite possible to get multiple requests simultaneously and I don't want the application to wait around dealing with requests individually.
There's the Threaded Fortune Server Example
Should get you started 😉
-
It has been deprecated, but you can also look at libmicrohttpd, it is a small footprint HTTP server implementation. Some good libraries have been built on it such as https://github.com/etr/libhttpserver to implement REST, etc.. Although they are standard C++, you can certainly use QT inside them.