Sent a message from C# to QT

640 Views Asked by At

I need to send a string line from a C# client (3.5) to a QT server. Everything works ok except one thing that on the server side I have to check a size of the line which is first 2 bytes. (I can't just make an infinite loop of listing the client). I try to put the size of the line to a first byte of the line but it reads wrongly on the server side. So the question is how to put a length of the string into first 2 bytes of the string?.

In QT it's done like this:

QByteArray arrBlock;
QDataStream out(&arrBlock, QIODevice::WriteOnly);
out << quint16(0) << "string";
out.device() -> seek(0);
out << **quint16(arrBlock.size() - sizeof(quint16));**
socket->write(arrBlock);

but in C# it's only

NetworkStream serverStream;
byte[] bytes = ...GetBytes("string");
serverStream.write
serverStream.flush

I couldn't find the way to write size to a message to the server.

0

There are 0 best solutions below