This is the receiver
void Dialog::tcpReady()
{
while(socket.bytesAvailable() > 0)
{
ds << ar;
}
file.close();
}
void Dialog::tcpReady()
{
QFile file("linux.png");
while(socket.bytesAvailable() > 0)
{
QByteArray ar=socket.readAll();
file.open(QIODevice::WriteOnly);
QDataStream ds(&file);
ds.setVersion(QDataStream::Qt_4_6);
ds << ar;
}
file.close();
}
To copy to clipboard, switch view to plain text mode
This is the Sender
void ServerThread::run()
{
if( !socket.setSocketDescriptor( m_descriptor ) )
{
qDebug( "Socket error!" );
return;
}
{
qDebug("Cannot open file!");
return;
}
int size=data.size();
quint32 b= quint32(data.size() - sizeof(quint32));
sizeBytes.append(b);
sizeBytes.append(data);
socket.write(sizeBytes);
socket.waitForDisconnected();
}
void ServerThread::run()
{
QTcpSocket socket;
if( !socket.setSocketDescriptor( m_descriptor ) )
{
qDebug( "Socket error!" );
return;
}
QFile file("linux.png");
if (!file.open(QIODevice::ReadOnly))
{
qDebug("Cannot open file!");
return;
}
QByteArray data=file.readAll();
int size=data.size();
QByteArray sizeBytes;
quint32 b= quint32(data.size() - sizeof(quint32));
sizeBytes.append(b);
sizeBytes.append(data);
socket.write(sizeBytes);
socket.waitForDisconnected();
}
To copy to clipboard, switch view to plain text mode
Bookmarks