请问在CAsyncSocket 的OnReceive(int nErrorCode)中, 能不能用ReceiveFrom?
为什么我用了, 机器陷入了死循环?
这是为何
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




