_sok = new QTcpSocket(); int i = 0; while(true) { QByteArray block; QDataStream out(&block, QIODevice::WriteOnly); out << (qint16)0; out << (QByteArray) QByteArray::number(i); out.device()->seek(0); out << (quint16)(block.size() - sizeof(quint16)); _sok->waitForBytesWritten(); i++; if(i > 1000) break; }
void MyThread::readyRead(){ QDataStream in(socket); qint16 size; in >> size; qDebug() << "size" << size; QByteArray bytes; in >> bytes; qDebug() << "bytes" << bytes; bytes.clear();}
connect(socket, SIGNAL(readyRead()), SLOT(newData()));....void newData(){ while(socket->bytesAvailable()) { QDataStream in(socket); QString str; in >> str; .... }....}