qt c++ send 6 bytes using tcp protocol

178 Views Asked by At

Hi everybody, first of all I'm new on network programming so maybe this is a simple question, but I don't get it. I try to send 6 Bytes to a microcontroller using tcp socket. In order to serialize my data I'm using qdatastream and qbytearray. That's the way I try to do this:

QByteArray buffer;
QDataStream outputStream(&buffer, QIODevice::WriteOnly);
outputStream.setVersion(QDataStream::Qt_5_8);
outputStream << (quint8) 0
             << (quint8) dataMessage.prefix
             << (quint8) dataMessage.paramID
             << (quint32) dataMessage.data;
outputStream.device()->seek(0);
outputStream << (quint8)(buffer.size() - sizeof(quint8));
qDebug() << buffer;
qDebug() << quint32(dataMessage.data);
sock->write(buffer);

if(sock->write(buffer) == -1)
{
    return -1;
}
sock->flush();

My struct dataMessage looks like this for example: dataMessage={15,1,9400000} Well in my buffer I would expect this Byte sequence "\x06\xF0\x01\x00\x8F\6E\xC0" but I always get the following Output "\x06\xF0\x01\x00\x8Fn\xC0".

What am I doing wrong?

0

There are 0 best solutions below