I am trying to send 2 request one by one at same time. My code is following (this is example code):
...
client->write(block);
client->write(block);
QTcpSocket client;
...
client->write(block);
client->write(block);
To copy to clipboard, switch view to plain text mode
Problem is following. Server receives only first request. There is no second request. I sniffed using wireshark and see that there is no second request in tcp packets.
What must i do to send many requests via QTcpSocket one by one?
Added after 29 minutes:
I inserted qDebug() << this->bytesAvailable() << "bytes"; to server in readyRead() and qDebug() << this->bytesToWrite(); after each client->write(block); in client. Also, I added this to client:
connect(this, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWritten(qint64)));
void Connection::bytesWritten(qint64 count)
{
qDebug() << count << "bytes written";
}
connect(this, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWritten(qint64)));
void Connection::bytesWritten(qint64 count)
{
qDebug() << count << "bytes written";
}
To copy to clipboard, switch view to plain text mode
I send ORDER_STATUS_GET_LIST constant in first request and ORDER_GET_LIST in second. I added data output in server. I received first command.
There is output listing:
Client:
Sending ORDER_STATUS_GET_LIST
11 bytes to write
Sending ORDER_GET_LIST
68 bytes to write
68 bytes written
Sending ORDER_STATUS_GET_LIST
11 bytes to write
Sending ORDER_GET_LIST
68 bytes to write
68 bytes written
To copy to clipboard, switch view to plain text mode
Server:
68 bytes
ORDER_STATUS_GET_LIST received
68 bytes
ORDER_STATUS_GET_LIST received
To copy to clipboard, switch view to plain text mode
Added after 17 minutes:
I found solution myself. I think that somebody needs this too.
Solution is simple:
...
client->write(block);
client->flush();
client->write(block);
client->flush();
QTcpSocket client;
...
client->write(block);
client->flush();
client->write(block);
client->flush();
To copy to clipboard, switch view to plain text mode
This is happen because QT tcp buffer is not empty when second request is executed.
Bookmarks