Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Client stay listen to port
I am developing an application that connects toserver with https requests written in c ++. I have sended data to the same server, using the QNetworkAccessManager and QNetworkRequest classes. I would like to use the same classes or subclasses of qnetworkto stay listening from server in a certain port, that is, I remian to listen until the server sends me a request. I can't use sockets because communication is based on https requests. Which strategy and which subclass should I use to listen on a particular port? Is it possible to use signal and slot? that is enter in slot when the server send me arequest. Can you post me a small example?
I kindly ask you if you can answer me in a short time.
Thanks for the support
Hi and welcome to devnet,
Can you explain how you are expecting your server to send you a request ?
Pablo J. Rogina last edited by
I can't use sockets because communication is based on https requests
Do you mean WebSockets? If so, you can use the WebSocket Secure (wss) protocol
The server send me a request GET http in a determined url and port (example: http://22.214.171.124:80/). The body request http is customized from the server, for example :
"firtName" : "James",
"secondName" : "Red"
I can't use the socket because i receive from the server only request https. That is if i received a request GET from the server i must response direclty a this reuqst open from the server, so i can't open a new channel of the communication because the server already opened one. I hope I have clearly answered your question.
Can you help me ?
Pablo J. Rogina last edited by
if i received a request GET from the server
Usually, it's all the way around; that is, a client sends an HTTP(S) request (GET or POST for instance) to a server, which fulfills such request and provides a response back to the client.
You may want to look at the Qt network examples , and also check additional documentation about client-server concepts.
In my case the client has a double function, that is send requests and risponses at the server and in addition, it must stay to listen to the server. I can't develop this part, where i must remain in listen from server, that is wait that the server send me (at client) the requests https.
I thought this solution:
QNetworkAccessManager *managerLis = new QNetworkAccessManager(this);
const QUrl url(QStringLiteral("http://126.96.36.199:8080")); QNetworkRequest request(url); connect(managerLis, SIGNAL(finished(QNetworkReply*)), this, SLOT(splitServerReq(QNetworkReply*)));
void remoteServer_ShortTest2::splitServerReq(QNetworkReply *reply)
// i client read request from the server
It's correct ?
No that is not how things are done.
QNetworkAccessManager is for client to server communication.
What you describe is that your application shall act as server as well as client just like your remote server shall act as client with your application.
That architecture is quiet strange. Why do you need such a strange two way communication setup ?
Why does your server need to act as client back to your application ?
Thanks you, i resolved my problems using the class httpServer.