-2
我有一个服务器(调用servera)接收从另一个服务器端文件发送到客户端的问题。问题是,客户端文件大小接收0,因此零个字节的文件:发送文件套接字C linux
/* receive file size from serverB */
recv(s,&bytes,sizeof(bytes),0);
/* send file size to client */
send(file_descriptor,&bytes,sizeof(bytes),0);
bytes = ntohs(bytes);
/* receive (from serverb) and send immediately (to client)*/
while (total != bytes) {
nread = read(s,&c,sizeof(char));
if(nread == 1){
send(file_descriptor,&c,sizeof(c),0);
total += nread;
}
}
有什么不对?
为了帮助诊断问题,我建议让Wireshark和看流量。 –
检查'recv'的结果。它可能比你想要的要少(或者对错误负面)。另外,了解如'poll'的多路复用系统调用。阅读http://advancedlinuxprogramming.com/ –
如何在接收缓冲区中有一个字节的情况下,尽快利用poll进行接收和发送? – user2510406