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:
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);
}
}
}
void Mainapp::newConnection()
{
QTcpSocket *socket = server->nextPendingConnection();
QFile file("C:/Qt/DB2");
file.remove();
file.open(QIODevice::Append);
socket->waitForReadyRead(1000);
qDebug()<<"hello kitty";
while(socket->bytesAvailable())
{
qDebug()<<"yes";
QByteArray bytes = socket->readLine();
file.write(bytes);
}
socket->close();
}
void Mainapp::broadcastDatagram()
{
QString str;
foreach (const QHostAddress &address, QNetworkInterface::allAddresses()) {
if (address.protocol() == QAbstractSocket::IPv4Protocol && address != QHostAddress(QHostAddress::LocalHost))
{
udpSocket->writeDatagram("127.0.0.1", QHostAddress::Broadcast, 45454);
}
}
}
To copy to clipboard, switch view to plain text mode
The client code is:
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();
}
void Datafeed::connected()
{
qDebug()<<"Connected...";
QFile myFile("C:/Qt/DB");
myFile.open(QIODevice::ReadOnly);
QByteArray data= myFile.readAll();
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out << (quint32)0;
out.device()->seek(0);
out << (quint32)(block.size() - sizeof(quint32));
msocket->write(data);
qDebug()<<data.data();
}
To copy to clipboard, switch view to plain text mode
Thanks in advance for any help.
Bookmarks