Hello,
I want to implement a TCP client connection that can recieve messages and reponses. For that I use a Qqueue for putting the response of my request and I use the readyRead signal to see if there are incoming response/requests.
My code looks as follows
connect(tcpSocket,SIGNAL(readyRead()),this, SLOT(readData()));
......
response_ptr Client
:: sendRequest(QByteArray const &data
) {
qDebug() << "Request: " << data.constData();
tcpSocket->write(data);
while(response_queue.isEmpty()) {}
return response_ptr(response_queue.dequeue());
}
void Client::readData() {
.....
// Read response an put it on the queue
response_queue.queue(response)
}
.....
connect(tcpSocket,SIGNAL(readyRead()),this, SLOT(readData()));
......
response_ptr Client:: sendRequest(QByteArray const &data) {
qDebug() << "Request: " << data.constData();
tcpSocket->write(data);
while(response_queue.isEmpty()) {}
return response_ptr(response_queue.dequeue());
}
void Client::readData() {
.....
// Read response an put it on the queue
response_queue.queue(response)
}
.....
To copy to clipboard, switch view to plain text mode
if I run the code and call "sendRequest", I come into a loop. Using wireShark I see that the request isn't send to the server.It seems that QT doesn't create a thread for listening to incoming data. I think that everything is running on the same thread ? So do I need to create a thread for listening on incoming messages/ responses ?
Bookmarks