C++ (Qt) while(curNumber*_blockSize<=_FileSize) { qint64 a=_FileSize-curNumber*_blockSize; int blockSize = qMin(a,_blockSize); QByteArray filearr=FileForSend->read(blockSize); sock->write(filearr); curNumber++; }
C++ (Qt)quint64 currentSize=0,curBytesAv=0; while(currentSize < FileSize){ curBytesAv=socket->bytesAvailable(); if(curBytesAv>0){ QByteArray arr; arr = sock->read(curBytesAv); if(curBytesAv==arr.size()){ FileForRec->write(arr); currentSize+=curBytesAv; } } if(currentSize < FileSize) sock->waitForReadyRead(); }
QString ipAddress; QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses(); for (int i = 0; i < ipAddressesList.size(); ++i) { if (ipAddressesList.at(i) != QHostAddress::LocalHost && ipAddressesList.at(i).toIPv4Address()) { ipAddress = ipAddressesList.at(i).toString(); ui.hosts->addItem(ipAddress); } }
void FTClient::sendPartOfFile() { sendFile->open(QFile::ReadOnly); QDataStream read(sendFile); long int lBytes = 0; char * ch; ch = (char*)malloc(sizeof(char) * 1024); //ch[1023] = '\0'; while(!read.atEnd()){ int l = read.readRawData(ch, sizeof(char)*1024); QByteArray ba(ch, sizeof(char)*l); lBytes += m_tcpSocket->write(ba, sizeof(char)*l); bool is = m_tcpSocket->waitForBytesWritten(); m_tcpSocket->flush(); if (-1 == lBytes){ qWarning() << "Error"; m_tcpSocket->close(); //Закрываем устройство сокета return; } /* float procentage = ((float)lBytes / package.filelength) * 100; emit setProcentage((int)procentage);*/ }//while(!readEnd()) free((void*)ch); closeConnection();}