使用CSocket类,客户端如何接收来自服务端的数据?

shixianpeng 2010-11-05 08:51:11
使用CSocket类,客户端如何接收来自服务端的数据?


客户端:
void CClientSocket ::CClientSocket()
{
}

CClientSocket * pClientSocket;

pClientSocket = new CClientSocket();
pClientSocket ->Create();

struct sockaddr_in svr;
server.sin_port = htons(1000);
int nRet = connect(*(pClientSocket ),(const struct sockaddr *)&svr,sizeof(svr));

char buff[1024];
pClientSocket->Send(buff,1024,0);

//接收服务器端数据,如何实现?
????????????????

接收端:
CListenSocket * pListenSocket;
pListenSocket= new CListenSocket ();
pListenSocket->Create(1000,SOCK_STREAM);
pListenSocket->Listen();

void pListenSocket::OnAccept(int nErrorCode)
{
CSocketRevice * precvsocket = new CSocketRevice();
  Accept(*precvsocket);
}

void pListenSocket::OnReceive(int nErrorCode)
{
char buff[1024];

//收到数据后,发送信息给客户端
  Send(buff,1024,0));
}
...全文
125 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zyb1369685 2010-12-01
  • 打赏
  • 举报
回复
这么贵,下载不了啊
shetianlang2010 2010-12-01
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 visualeleven 的回复:]
CAsyncSocket::OnReceive

Called by the framework to notify this socket that there is data in the buffer that can be retrieved by calling the Receive member function.

virtual void OnReceive(
……
[/Quote]

发现此人全才
cibiren2009 2010-11-05
  • 打赏
  • 举报
回复
这是一个基本的问题,你的OnReceive函数里面,调用了接受函数Receive么?



void pListenSocket::OnReceive(int nErrorCode)
{
char buff[1024];
Receive(buff,1024); //是否没有调用这个函数? //收到数据后,发送信息给客户端
  Send(buff,1024,0));
}
【天运子】 2010-11-05
  • 打赏
  • 举报
回复
http://download.csdn.net/source/2373543 发过了 另个贴 这是我用CSocket实现的文件传输 里面有你要的 如何发送数据 接收数据
shixianpeng 2010-11-05
  • 打赏
  • 举报
回复
服务器端发送后,客户端OnReceive 里没反应
OnReceive
Eleven 2010-11-05
  • 打赏
  • 举报
回复
CAsyncSocket::OnReceive

Called by the framework to notify this socket that there is data in the buffer that can be retrieved by calling the Receive member function.

virtual void OnReceive(
int nErrorCode
);

ouyh12345 2010-11-05
  • 打赏
  • 举报
回复
客户端也有OnReceive

18,356

社区成员

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

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