mfc socket传输文件的问题??

yyyy5607 2010-12-13 11:23:29
从网上找到这一段内容:
发送端: 
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); //自动就写到文件末尾了
}




现在有一个问题: 发送文件时send中有四个要定义的函数,
请问其中的第二个函数应该如何填写呢?是写文件名还是?它的原理又是怎样的呢?
...全文
123 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Eleven 2010-12-13
  • 打赏
  • 举报
回复
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.
fishion 2010-12-13
  • 打赏
  • 举报
回复
先看下,windows网络编程
ouyh12345 2010-12-13
  • 打赏
  • 举报
回复
当然传数据
superhanxin5 2010-12-13
  • 打赏
  • 举报
回复
buf是你要传送的的数据缓存的指针。
你需要把你要传输的数据转到一个缓存中,相当于一个容器,过渡用

[Quote=引用 3 楼 visualeleven 的回复:]
C/C++ code
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 buff……
[/Quote]
licky91 2010-12-13
  • 打赏
  • 举报
回复
图书商城模板图书商城模板图书商城模板
yyyy5607 2010-12-13
  • 打赏
  • 举报
回复
请问有没有这方面的示例呀?

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧