Unable to send database file over LAN
Hi All,
I am developing a LAN application using Qt on Windows, I need to send a database file from clients to the server but I am unable to send the file properly the server is only receiving incomplete file or only signature of file which I am able to see in the destination folder but the file is empty.
The server code is:
Code:
void Mainapp::newConnection()
{
QTcpSocket *socket
= server
->nextPendingConnection
();
file.remove();
socket->waitForReadyRead(1000);
qDebug()<<"hello kitty";
while(socket->bytesAvailable())
{
qDebug()<<"yes";
file.write(bytes);
}
socket->close();
}
void Mainapp::broadcastDatagram()
{
{
udpSocket
->writeDatagram
("127.0.0.1",
QHostAddress::Broadcast,
45454);
}
}
}
The client code is:
Code:
void Datafeed::connected()
{
qDebug()<<"Connected...";
QFile myFile
("C:/Qt/DB");
out << (quint32)0;
out.device()->seek(0);
out << (quint32)(block.size() - sizeof(quint32));
msocket->write(data);
qDebug()<<data.data();
}
Thanks in advance for any help.
Re: Unable to send database file over LAN
You are assuming that the entire file arrives and is announced by a single readyRead() signal. This will not be the case and is the cause of your truncated file.
You are also treating your incoming data stream as if it was text, (e.g. With readline()) which is at odds with the QDataStream you used at the other end.