PDA

View Full Version : QTcpSocket read duplicate data, but only on "bad channel"



creatron
24th May 2010, 17:38
I have a client socket class defined as

class ClientSocket : public QTcpSocket
{
...
I write socket data as follows
code
write ((const char *) &buffer, data_packet.size + HEADER_SIZE);
while (waitForBytesWritten (100) == -1);
/code
(Note data_packet.size + HEADER_SIZE == 1024)

The same class is used in the client, receiving data connecting the readyRead signal to a slot

slot ..
code
index = 0;
forever {
amount = bytes_available();
if (amount > 0)
index + = read ((const char *)&buffer[0] + index, amount);
etc...
// until the total amount of bytes is read, Accumulated == 1024, break
}
/code

process the data
// the data is incorrect at this point

I only send/receive 1024 bytes at a time, and make up the packets with a packet number and number of packets in the header, the last packet is the one where packet number == number of packets

My problem is as follows:

Using a local net work I can send and receive data (files small and big) for days on end without a problem, I could even use my ADSL via a 3G modem without any problem. then I turn to IBurst.

( IBurst is a RF network, and is renowned for snail mail, and very slow connections, an ideal test platform to test your software over a bad medium).

If I write the data using waitForBytesWritten to determine if I can write a new packet, the connections falls over almost immediately. on a bad day. If I wait 300ms between writes, the system perform better, but not alwaysreceive the correct data . The problem is that I get the same data (the packet number is the same) from the read on the receiver side. The wait time is a bad fix, as if the channel get bad, the time needs to be increased more. and one always send /receive file at a snail place.

I cannot understand the problem as a TCP socket class should sort out the packet buffering. The receiver should get a signal and read the correct data, even if it is less than the packet size, until you have the correct amount.

Any ideas ?

Thanks in advance
Gerrie

tbscope
24th May 2010, 19:17
I must admit that I know absolutely nothing of IBurst, but from reading a little bit on the net I wonder if TCP can be used on top of IBurst.