QTcp[server and socket]: can't read my transfered file, why!!
Good morning,
I tried to create my own code. I have an application, in which, the user will choose a file from his DD ( all types) and send it to the TcpServer, this server will then send this file to the other clients.But, I have a problem, when i choose the file and i send it, in the client’s side, i have this message: file is sending , but in the server’s side, it shows me that the file isn’t recieved with it’s totaly bytes. Any suggestion please. This is the function for sending the file in the client’s side:
Code:
void FenClient::on_boutonEnvoyer_2_clicked()
{
QString nomFichier
= lineEdit
->text
();
QFile file(lineEdit
->text
());
{
qDebug() << "Error, file can't be opened successfully !";
return;
}
out << quint32(0);
out << nomFichier;
out << bytes;
out.device()->seek(0);
out << quint32((block.size() - sizeof(quint32)));
qDebug() << "Etat : envoi en cours...";
listeMessages->append("status : sending the file...");
socket->write(block);
}
and the server side:
Code:
void FenServeur::datarecieved()
{
QTcpSocket *socket
= qobject_cast<QTcpSocket
*>
(sender
());
if(socket == 0)
{
qDebug() << "no Socket!";
return;
}
forever
{
if(blockSize == 0)
{
if(socket->bytesAvailable() )
{
qDebug() << "Error < sizeof(quint32))";
return;
}
in >> blockSize;
}
if(socket->bytesAvailable() < blockSize)
{
qDebug() << "data not recieved with its total bytes";
return;
}
qDebug() << "!!!!!!";
in >> nameFile >> dataOut;
fileOut.write(dataOut);
fileOut.close();
blockSize = 0;
}
}
void FenServeur
::sendToAll(const QString &message
) {
out << (quint32) 0;
out << message;
out.device()->seek(0);
out << (quint32) (paquet.size() - sizeof(quint32));
for (int i = 0; i < clients.size(); i++)
{
clients[i]->write(paquet);
}
}
So i can't write the file that the server recieved into a new file, or i have to write it in a filejust in the client side!!!. Any suggestion please!! and thanks in advance
Re: QTcp[server and socket]: can't read my transfered file, why!!
Do you think posting the same problem in two threads is going to give you twice as many solutions to your problem?
http://www.qtcentre.org/threads/5135...read-file-sent
Re: QTcp[server and socket]: can't read my transfered file, why!!
certainly no :eek: , i tried to delete the other post, but i couldn't do it , sorry