怪事,不信试试
从CAsyncSocket派生一个类,重载OnReceive(),在OnReceive()中用ReceiveFrom接受数据。用SendTo向此程序发送数据一切正常。
但一旦SendTo中发送的数据长度为0,比如SendTo(buf,0,5000,"127.0.0.1"),那么OnReceive()就再也不响应了,以后再发送数据函数体根本就不执行了,连判断错误的机会都没有,这是为什么啊?是微软的Bug?
请各位试试!看看怎样解决。
问题点数:0、回复次数:16Top
1 楼qing_li73(Vincent Lee)回复于 2003-02-04 01:09:17 得分 0
If no error occurs, SendTo returns the total number of characters sent. (Note that this can be less than the number indicated by nBufLen.) Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling GetLastError. The following errors apply to this member function:
WSANOTINITIALISED A successful AfxSocketInit must occur before using this API.
WSAENETDOWN The Windows Sockets implementation detected that the network subsystem failed.
WSAEACCES The requested address is a broadcast address, but the appropriate flag was not set.
WSAEINPROGRESS A blocking Windows Sockets operation is in progress.
WSAEFAULT The lpBuf or lpSockAddr parameters are not part of the user address space, or the lpSockAddr argument is too small (less than the size of a SOCKADDR structure).
WSAEINVAL The host name is invalid.
WSAENETRESET The connection must be reset because the Windows Sockets implementation dropped it.
WSAENOBUFS The Windows Sockets implementation reports a buffer deadlock.
WSAENOTCONN The socket is not connected (SOCK_STREAM only).
WSAENOTSOCK The descriptor is not a socket.
WSAEOPNOTSUPP MSG_OOB was specified, but the socket is not of type SOCK_STREAM.
WSAESHUTDOWN The socket has been shut down; it is not possible to call SendTo on a socket after ShutDown has been invoked with nHow set to 1 or 2.
WSAEWOULDBLOCK The socket is marked as nonblocking and the requested operation would block.
WSAEMSGSIZE The socket is of type SOCK_DGRAM, and the datagram is larger than the maximum supported by the Windows Sockets implementation.
WSAECONNABORTED The virtual circuit was aborted due to timeout or other failure.
WSAECONNRESET The virtual circuit was reset by the remote side.
WSAEADDRNOTAVAIL The specified address is not available from the local machine.
WSAEAFNOSUPPORT Addresses in the specified family cannot be used with this socket.
WSAEDESTADDRREQ A destination address is required.
WSAENETUNREACH The network cannot be reached from this host at this time.
Top
2 楼myusst(Random)回复于 2003-02-04 11:46:03 得分 0
跟SendTo有什么关系,SendTo照样好用,问题出在的是OnReceive()上没有反应了,不要乱复制一段MSDN就了事了。Top
3 楼Richuen22(Vista)回复于 2003-02-04 23:38:23 得分 0
试一试,明天晚上答复。Top
4 楼everandforever(Forever)回复于 2003-02-05 13:49:50 得分 0
就算有这种问题,你SENDTO之前判断一下是否为0,为0就不发,不就得了?何必在这上面浪费时间。Top
5 楼myusst(Random)回复于 2003-02-05 21:27:53 得分 0
这算什么话,那如果哪个恶意程序要攻击服务器端,那只要SendTo发一个长度为0的数据包,那服务器端不就瘫痪了!!!Top
6 楼everandforever(Forever)回复于 2003-02-06 00:30:54 得分 0
Calling sendto with a len of zero is permissible and will return zero as a valid value. For message-oriented sockets, 《《a zero-length transport datagram is sent.》》
__________________
CASYNCSOCKET类在发现有数据来时,会先用 IOCTL(..,FIONREAD,..)来获取发来的数据的尺寸。如果尺寸为0,那么就不会调用RECEIVEFROM()/RECEIVE()。 我想,是不是发来了一个0长度的包,但是这个包却总也没有被读出来造成的?Top
7 楼myusst(Random)回复于 2003-02-06 12:24:44 得分 0
那如何解决呢,OnReceive根本没有响应,怎样知道发过来的数据包长度为0,怎样读出来呢?Top
8 楼gordonstysty(gordon)回复于 2003-02-06 12:50:42 得分 0
关注中Top
9 楼yydyqy(行情一年不如一年)回复于 2003-02-06 14:51:14 得分 0
gzTop
10 楼natureshuo()回复于 2003-02-06 23:13:49 得分 0
gzTop
11 楼Richuen22(Vista)回复于 2003-02-07 01:45:10 得分 0
不好意思,恐怕要几天才行。Top
12 楼everandforever(Forever)回复于 2003-02-07 02:23:31 得分 0
不用 CAsyncSocket 。这不是很难Top
13 楼myusst(Random)回复于 2003-02-07 12:40:28 得分 0
难道就没有方法解决了吗?Top
14 楼everandforever(Forever)回复于 2003-02-07 12:48:54 得分 0
如果的确是我说的那个原因的话,你就得替换CASYNCSOCKET内建的窗口的窗口WNDPROC了。这恐怕比不用CASYNCSOCKET还麻烦。Top
15 楼yyszh(追求完美)回复于 2003-02-07 14:12:31 得分 0
这肯定是CAsyncSocket的错,只好不用它了。Top
16 楼awnucel(西大耻犹未雪,南京恨何时灭&抵制日货)回复于 2003-02-11 14:01:06 得分 0
up
Top




