CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  网络编程

请问在CAsyncSocket 的OnReceive(int nErrorCode)中, 能不能用ReceiveFrom?

楼主longlijun(风之力)2005-08-03 21:36:53 在 VC/MFC / 网络编程 提问

为什么我用了,   机器陷入了死循环?  
  这是为何  
   
  SOCKADDR   client;  
  int   len   =   0;  
   
  DEBUGOUT(buf);  
  ReceiveFrom(buf,   sizeof("GetMyData"),   &client,   &len);  
   
  DEBUGOUT("Receiving");  
   
   
  结果是DEBUGVIEW,   出现了满屏的Receiving  
  而使用Receive则不会,    
  我不能使用Receive,   因为,   我还需要知客户机地址 问题点数:100、回复次数:4Top

1 楼longlijun(风之力)回复于 2005-08-03 21:38:16 得分 0

SOCKADDR   client;  
  int   len   =   0;  
   
  ReceiveFrom(buf,   sizeof("GetMyData"),   &client,   &len);  
   
  DEBUGOUT("Receiving");Top

2 楼dirdirdir3(风)回复于 2005-08-03 22:26:13 得分 0

我还需要知客户机地址,要知道客户机地址很容易啊,用GetPeerName()就可以知道了啊,用Receive。  
  ReceiveFrom()是用于UDP的,不同的东西。Top

3 楼longlijun(风之力)回复于 2005-08-04 08:07:48 得分 0

我用的就是UDP,   对方是SendTo发过来的Top

4 楼hyamw(林锋)回复于 2005-08-04 08:43:05 得分 100

int   ReceiveFrom(   void*   lpBuf,   int   nBufLen,   SOCKADDR*   lpSockAddr,   int*   lpSockAddrLen,   int   nFlags   =   0   );  
  参数lpSockAddrLen的内容所指向的内容应该是lpSockAddr所指向的结构体的大小。  
  lpSockAddrLen  
   
  A   pointer   to   the   length   of   the   source   address   in   lpSockAddr   in   bytes.  
  If   lpSockAddr   is   nonzero,   and   the   socket   is   of   type   SOCK_DGRAM,   the   network   address   of   the   socket   which   sent   the   data   is   copied   to   the   corresponding   SOCKADDR   structure.   The   value   pointed   to   by   lpSockAddrLen   is   initialized   to   the   size   of   this   structure,   and   is   modified   on   return   to   indicate   the   actual   size   of   the   address   stored   there.   If   no   incoming   data   is   available   at   the   socket,   the   ReceiveFrom   call   waits   for   data   to   arrive   unless   the   socket   is   nonblocking.   In   this   case,   a   value   of   SOCKET_ERROR   is   returned   with   the   error   code   set   to   WSAEWOULDBLOCK.   The   OnReceive   callback   can   be   used   to   determine   when   more   data   arrives.    
   
   
   
  //所以你应该做如下修改:  
  int   len   =   sizeof(SOCKADDR_IN);Top

相关问题

  • CAsyncSocket::OnReceive 问题
  • CSocket UDP 编程时,在OnReceive(int nErrorCode)事件里用ReceiveFrom,程序就死掉了,阻塞了?
  • 关于CAsyncSocket:OnReceive()函数
  • CSocket::OnReceive(int nErrorCode)何时被调用?
  • CAsyncSocket?
  • CCeSocket或CSocket或CAsyncSocket 在wince3.0 下如何实现自动响应OnReceive()
  • 我用CAsyncSocket 做一server,怎样听Accept(newClienSock) 的 newClienSock的OnReceive实事件?
  • 如何控制CAsyncSocket的onreceive事件,使它一次只接受一个数据包
  • 如何在void mysocket::OnReceive(int nErrorCode)函数中判断是TCP还是UDP从而触发不同的函数呢?是否有其它办法?
  • CAsyncSocket中的GetPeerName

关键词

  • 客户机
  • client
  • socket
  • receivefrom
  • debugout
  • lpsockaddrlen
  • lpsockaddr
  • sockaddr
  • receive
  • 客户机地址

得分解答快速导航

  • 帖主:longlijun
  • hyamw

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo