I am making a simple file transfer app based on Threaded Fortune Server. I am running into an issue where I am losing the last couple of bytes from my file.
Client Code:
DataStream infile(&file);
DataStream in(socket);
int count = 0;
char point[1500];
while(!infile.atEnd())
{
count = infile.readRawData(point,1500);
in.writeRawData(point,count);
TCPSocket->waitForBytesWritten(300);
}
file.open(QIODevice::ReadOnly);
DataStream infile(&file);
DataStream in(socket);
int count = 0;
char point[1500];
while(!infile.atEnd())
{
count = infile.readRawData(point,1500);
in.writeRawData(point,count);
TCPSocket->waitForBytesWritten(300);
}
To copy to clipboard, switch view to plain text mode
Server Side:
This function is connected to readyRead
void ReadNow{
char point[1500];
int count = 0;
while(!input.atEnd())
{
count = input.readRawData(point,1500);
totalbytes+=count;
output.writeRawData(point,count);
}
file.waitForBytesWritten(1000);
}
void ReadNow{
QDataStream input(socket);
QDataStream output(file);
char point[1500];
int count = 0;
while(!input.atEnd())
{
count = input.readRawData(point,1500);
totalbytes+=count;
output.writeRawData(point,count);
}
file.waitForBytesWritten(1000);
}
To copy to clipboard, switch view to plain text mode
I am unsure of where the missing bytes are going.
Bookmarks