• 5949阅读
  • 3回复

QTcpSocket问题求助!!! [复制链接]

上一主题 下一主题
离线reback
 
只看楼主 倒序阅读 楼主  发表于: 2009-04-01
— 本帖被 XChinux 从 General Qt Programming 移动到本区(2011-01-02) —
用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().

谁知道该怎么设计才能达到我想要的目的呢?有数据来就全部追加到本地缓存里?然后循环读缓存里的包,直到缓存里没有一个完整的包?
离线reback
只看该作者 1楼 发表于: 2009-04-02
顶自己,高手快来
离线zhshzhjhust
只看该作者 2楼 发表于: 2009-04-03
同时发送两数据包是什么意思?
离线qimo601

只看该作者 3楼 发表于: 2012-02-25
这个就是你自己定义协议的问题了。
同时发送2个小数据包,你肯定会接收到两次ReadyRead()信号。
把这两个数据包,一个个读取,组成一个你想要的数据结构就行啊。


一个老话题我不小心搜到的哈哈哈
快速回复
限100 字节
 
上一个 下一个