ok, i use it this way:
server send-method
void Server
::send_xml_data(QString message
) { blockSize = 0;
out_stream << (qint16)0;
out_stream << out_string;
out_stream.device()->seek(0);
out_stream << quint16(block.size() - sizeof(quint16));
socket->write(block);
}
void Server::send_xml_data(QString message) {
blockSize = 0;
QString out_string = message;
QByteArray block;
QDataStream out_stream(&block, QIODevice::WriteOnly);
out_stream.setVersion(QDataStream::Qt_4_7);
out_stream << (qint16)0;
out_stream << out_string;
out_stream.device()->seek(0);
out_stream << quint16(block.size() - sizeof(quint16));
socket->write(block);
}
To copy to clipboard, switch view to plain text mode
client-readyReadSlot-method:
void Client::readyReadSlot()
{
qDebug() << "readyReadSlot()";
if (blockSize == 0) {
if (socket->bytesAvailable() < (int)sizeof(quint16))
return;
in >> blockSize;
}
if (socket->bytesAvailable() < blockSize)
return;
in >> result;
receive(result); //process my data
}
void Client::readyReadSlot()
{
qDebug() << "readyReadSlot()";
QDataStream in(socket);
in.setVersion(QDataStream::Qt_4_7);
if (blockSize == 0) {
if (socket->bytesAvailable() < (int)sizeof(quint16))
return;
in >> blockSize;
}
if (socket->bytesAvailable() < blockSize)
return;
QString result;
in >> result;
receive(result); //process my data
}
To copy to clipboard, switch view to plain text mode
Bookmarks