Re: Formatting a packet with different types then send it over TCP
So what happens in the second while loop if all your bytes arrived at once and were available when you entered the routine? What about if only some of the message bytes have been received? What if some of the bytes are delayed?
Have you set a breakpoint and single-stepped this?
Re: Formatting a packet with different types then send it over TCP
The first loop to read 6 bytes(2 bytes + 4 bytes of size), in the second loop I block until I read the whole packet, so this all I get. If you have better solution please post it.
Re: Formatting a packet with different types then send it over TCP
Quote:
Originally Posted by
SIFE
in the second loop I block until I read the whole packet
What if two packets arrive at once?
Quote:
If you have better solution please post it.
My universal approach is to use signals and slots, buffer incoming data and process the buffer in a while loop as long as there is enough data in it.
Re: Formatting a packet with different types then send it over TCP
Quote:
My universal approach is to use signals and slots, buffer incoming data and process the buffer in a while loop as long as there is enough data in it.
Would you say it in code :D.
Re: Formatting a packet with different types then send it over TCP
If you want code then search the forum. I can give you a short explanation -- connect to the socket's readyRead() signal, append all pending data to your own buffer and process the buffer in a while loop according to the following pseudo-code logic:
Code:
buffer += socket.readAll();
while(buffer.size >= expectedBlockSize) {
data = buffer.take(expectedBlockSize);
process(data);
}
Of course expectedBlockSize will depend on what you expect to receive.