本文介绍了C:发送文件到套接字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用套接字发送二进制文件.
I`m trying to send binary file using socket.
FILE *file;
char *file_data;
file = fopen(filepath, "rb");
//Allocate memory
file_data=(char *)malloc(fileLen+1);
//Read file contents into buffer
fread(file_data, fileLen, 1, file);
fclose(file);
sent = send(client, file_data, strlen(header)+fileLen, 0);
它可以正常工作,但是某些文件太大,我想读取要缓冲的部分,发送,然后读取第二部分,发送,依此类推.
It works OK, but some files a too large and I want to read a part to buffer, send it, then read the second part, send it and so on.
我尝试使用fread和fgets来获得零件,但是我失败了=(如何正确执行?
I tried to get parts using fread and fgets, but i failed =( How to do it correctly?
UPD:问题在于读取客户端的传入请求.我没看过.如果我这样做,那没什么不好的事
UPD: the trouble was in reading incoming request from client. I didnt read it. If i do it, nothing bad happens
推荐答案
问题在于读取客户端的传入请求.我没看过.如果我这样做,那没什么不好的事
the trouble was in reading incoming request from client. I didnt read it. If i do it, nothing bad happens
这篇关于C:发送文件到套接字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!