Originally Posted by
wysota
Then why are you trying to read them as an integer?
I want to read it as binary. appending data length at the beginning with this:
void tcpClient::sendToServer()
{
data.append(5);
data.append("Saman");
if(clientSocket->write (data) == -1)
{
qDebug("write() failed");
}
}
void tcpClient::sendToServer()
{
QByteArray data;
data.append(5);
data.append("Saman");
if(clientSocket->write (data) == -1)
{
qDebug("write() failed");
}
}
To copy to clipboard, switch view to plain text mode
in the server, let's read the first 4 bytes, as the size of integer and then read the text.
int length;
clientConnection->read((char*)&length, 4);
qDebug() << length;
text.reserve(length);
clientConnection->read(text.data(), length);
clientConnection->flush();
QByteArray text;
int length;
clientConnection->read((char*)&length, 4);
qDebug() << length;
text.reserve(length);
clientConnection->read(text.data(), length);
clientConnection->flush();
To copy to clipboard, switch view to plain text mode
output:
length read is 1835094789 !
what am I missing?
Bookmarks