18,356
社区成员
发帖
与我相关
我的任务
分享
发送端:
int SendFileLength = 0;//保存已经发送的文件的长度
while (SendFileLength < filelength)
{
file.Seek(SendFileLength,CFile::begin);
sockSenderror = send(SendFileSock,buffer,TempSendLength,0);
if(SOCKET_ERROR == sockSenderror)
{
closesocket(SendFileSock);
return 0;
}
SendFileLength += TempSendLength;
}
接收端:
int finish=0;//保存receive函数的返回值
while(true)
{
finish = recv(ConnSock,buffer,BUFFERSIZE,0);//开始写入文件,
if(SOCKET_ERROR == finish)
{
AfxMessageBox("接收文件错误!");
return 0;
}
file.Write(buffer,finish); //自动就写到文件末尾了
}
int send(
__in SOCKET s,
__in const char* buf,
__in int len,
__in int flags
);
Parameters
s
A descriptor identifying a connected socket.
buf
A pointer to a buffer containing the data to be transmitted.
len
The length, in bytes, of the data in buffer pointed to by the buf parameter.
flags
A set of flags that specify the way in which the call is made.