用QTcpServer和QTcpSocket写了一个服务端和一个客户端,readyRead信号一来会先读协议头,根据协议头里的大小读后面的长度。使用中发现一个问题,如果一方同时发送2个小数据包,接收方接收到一个完整的数据包处理完后,退出函数等待下一个包。这时候,即使缓冲区里有数据,也不会再次收到readyRead信号。。。
QT的说明
The readyRead() signal is emitted every time a new chunk of data
has arrived. bytesAvailable() then returns the number of bytes
that are available for reading. Typically, you would connect the
readyRead() signal to a slot and read all available data there.
If you don't read all the data at once, the remaining data will
still be available later, and any new incoming data will be
appended to QAbstractSocket's internal read buffer. To limit the
size of the read buffer, call setReadBufferSize().
谁知道该怎么设计才能达到我想要的目的呢?有数据来就全部追加到本地缓存里?然后循环读缓存里的包,直到缓存里没有一个完整的包?