I am transferring a file from a PC server written in Qt to the android client. The client accepts the first couple of byte packets normally. And then the hellish lag from the server begins. Those. in the client almost all the time in.available() == 0 .
Previously, there was no such wild lag, the code seemed to be the same. flush returns true , and the client hangs in a loop with available=0 .
Internet speed on the client seems to be the same as on the PC, even more.
Sending a file briefly:
int len = file.size(); int writingBytes0 = 0; if (len > 8192) { while (1) { QByteArray b = file.read(8192); if (b.isEmpty()) { pClientSocket->flush(); break; } pClientSocket->write(b); bool fl = pClientSocket->flush(); writingBytes0 += b.size(); mw->setPrUn(writingBytes0); } } else { QByteArray b = file.read(len); //stream->writeRawData(b, b.size()); pClientSocket->write(b); mw->setPrUn(len); pClientSocket->flush(); } file.close(); The file acceptance code on the client:
long msize = file.length(); long writebites = 0; long writebites0 = msize; while (msize != writebites) { int avaibl = in.available(); if (avaibl > 0) { //вот тут отставание, и очень сильное if (avaibl < writebites0) { byte[] buf = new byte[avaibl]; in.read(buf); writebites = writebites + avaibl; fos.write(buf); writebites0 = writebites0 - avaibl; } else { byte[] buf = new byte[(int)msize]; in.read(buf); writebites = msize; fos.write(buf); writebites0 = 0; } } }