PDA

View Full Version : Packet handling advice with QTcpSocket?



zAAm
24th April 2010, 14:32
Hi

I'm currently developing a network application, and I've run into a few problems with my readyRead() handler. It works fine at low speeds, but it seems that once it receives a couple of packets at once it can start to corrupt the packet data?

I prepend a header portion (3 bytes) to each packet that includes a char at the front to identify the packet type and two bytes reserved for its size (quint16).

How can I optimize the code to work with large amounts of packets (and incomplete packets) per read?
Here's my readyRead() handler code: (It reads the packet and sends it to a specific UDP port on the localhost)

Thanks! :cool:

EDIT: It seems this isn't the problem as I compared precalculated checksums with checksum calculated after the block is received and they are identical. So if anything it might be the speed/order in which they are received/sent.

Kumosan
27th April 2010, 15:23
You are using UDP? Then the behaviour is totally correct. In UDP you have no guarantee in what order you receive sent packages.
http://www.cafeaulait.org/course/week12/35.html
You have to add something like a sequence number.