|
client端:QT写的 win7
server端:arm板
由client端传输 zip压缩文件到arm板上,后面调试发现,比较大的文件传输不完全,小文件基本没问题
client 端:发送
struct FilePackage sendPack;
bytesToWrite = 0; //已发送大小
totalBytes = localFile->size(); //文件总大小 字节单位
while (bytesToWrite < totalBytes)
{
//每次发送loadsize大小的数据,1K,如果剩余的数据不足1KB,就发送剩余数据的大小 1024
outBlock = localFile->read(qMin(totalBytes - bytesToWrite, loadSize));
sendPack = pack('U', outBlock.data(), currentFileName.toLocal8Bit().data(), outBlock.size(), 2, outBlock.size()); //打包
tcpClient->write((char *)&sendPack, sizeof(struct FilePackage)); //发送数据包
bytesToWrite += outBlock.size();
qDebug() << outBlock.size();
//清空发送缓冲区
outBlock.resize(0);
}
server端:接收
//创建文件 开始写入数据
if ((newfd = open(destfilename, O_RDWR|O_CREAT, 0777)) == -1)
{
perror("open: ");
close(newfd);
exit(1);
}
printf("create file success!\n");
//清空buf准备接收数据
bzero(&buff, sizeof(buff));
if ((recv(*client_fd, (char *)&buff, sizeof(struct FilePackage), 0)) == -1)
{
perror("recv");
fclose(fp);
exit(1);
}
//判断是否为文件数据
while (buff.ack == 2)
{
count = buff.filesize;
printf("filesize = %d\n", count);
recvbytes += count;
if ((write(newfd, buff.buf, count)) == -1)
{
perror("write error:\n");
close(newfd);
}
//printf("######\n");
bzero(&buff, sizeof(buff));
if ((recv(*client_fd, (char *)&buff, sizeof(struct FilePackage), 0)) == -1)
{
perror("recv");
close(newfd);
exit(1);
}
}
//上传完毕
if (buff.ack == 4)
{
printf("File %s transfer Success!\n", pfilename);
printf("recvbytes == %d\n", recvbytes);
close(newfd);
exit(1);
}
-------------------------------------------------------
小文件的传输基本没问题,就是大一点的文件,像1M++的话,就会停在recv函数这里,一直在读取
帮我看看,是发送有问题,还是接收有问题,
打印大概是:
小文件:
大文件:
就这样一直在读取
Ctrl+C 查看文件,才传输了几百K,文件实际大小有几M
调了好久了,大家帮忙看看,谢谢了。
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|