struct TPackageHeader{ int PackageNumber; int PackageSenderID; int PackageDataSize;};
void f(){ TPackage header; header.PackageDataSize = 1024; socket->write( &header, sizeof( header ) ); socket->write( data, header.PackageDataSize );}
for ( int i = 0; i < 100; i++ ) f();
for ( int i = 0; i < 100; i++ ){ f(); qApp->processEvents();}
//------------------------------------------------------------------------------void net::connection::io_dev_ready_read() // от сигнала readyRead(){ while(checkMessage()) { // msg ready for read qint32 _size=0; QByteArray data; qint64 _readed = p_ioDevice->read((char*) &_size, sizeof(_size)); if((sizeof(_size)==_readed) && (_size>0)) { if(_size > const_message_size_max) { qCritical() << "big message received " << _size << " bytes!"; this->resetState(); return; } data = p_ioDevice->read(_size); if(data.size() != _size) { qCritical() << "couldn't read full message"; this->resetState(); return; } emit evPacketReceived(data); } }}//------------------------------------------------------------------------------bool net::connection::checkMessage(){ qint64 _bytes_available = p_ioDevice->bytesAvailable(); if(_bytes_available<4) return false; qint32 _size=0; qint64 _peek_size = p_ioDevice->peek((char*)&_size, sizeof(_size)); if(_peek_size != sizeof(_size)) return false; _bytes_available = p_ioDevice->bytesAvailable(); if(_bytes_available < sizeof(_size) + _size) return false; return true;}
void ClientServer::receivePackage()
if (m_Client->bytesAvailable()) emit rereadData();
QTcpSocket::readyRead()