06-27-2006 11:06 AM
06-27-2006 03:02 PM
The lpNumberOfBytesRecvd parameter in WSARecvFrom will be updated only if WSARecvFrom() completes successfully. You can check the return value from WSARecvFrom() and call WSAGetLastError() if it is not 0.
You may not have a long enough timeout value set or you may be using WSARecvFrom() with an overlapped parameter. If you are using overlapped i/o the call can terminate and will return SOCKET_ERROR. You will probably get WSA_IO_PENDING from WSAGetLastError(), which means that the call has not completed. When an outstanding overlapped operation is eventually completed, you can get the number of bytes transferred with a call to WSAGetOverlappedResult. MSDN has more documentation.
If you post the relavant snippits of your code here, we can try and help you get it working.
06-27-2006 04:16 PM
The WSA functions are an asynchronous, non-blocking extention of the Berkeley sockets model that has been around in the Unix world for a long time. The old blocking Berkeley-style functions are still there if you want to use them and a lot of code intended for Unix style systems may work on a Windows platform with relatively few (if any) changes at the socket level.
Using the WSA style functions is a bit trickier as mvr points out. If you use them in non-overlapped mode, they will block and pretty much act almost the same way as the old-style functions. Using them in overlapped mode is where things get a bit harder. Unfortunately, the use of these functions is a lot more than I can go into right now. Fortunately, there is this reference on MSDN:
You will definitely want to read pretty much the whole overview section with the exception of the IPv6 and NLA stuff (unless you are using those).
I know this is really a just a matter of semantics but the function is returning a count of zero bytes, not NULL. While NULL is defined as zero, they are not semantically the same thing. A NULL is generally an invalid pointer While a zero is simply zero.
Anyway, that's just a bit of nit-picking but it is a useful convention.
06-28-2006 08:11 AM
06-28-2006 02:44 PM
06-28-2006 03:51 PM - edited 06-28-2006 03:51 PM
I assume lpdwDataBytesRecvd is a DWORD.
might want to set lpdwDataBytesRecvd =0, Flags=0, if they are not already initialized.
You need a pointer to lpdwDataBytesRecvd, was that a typo?
WSARecvFrom(RecvSocket, &DataBuf, 1, &lpdwDataBytesRecvd, &Flags, (SOCKADDR *) &SenderAddr,
&SenderAddrSize, &Overlapped, NULL)) ;
997 is IO_PENDING. If you are not overlapped you might want to see if your data buffer could be invalid or too small.
Message Edited by mvr on 06-28-2006 03:52 PM
06-29-2006 08:38 AM
06-30-2006 11:05 AM
Thanks for the attention, archieb
I find that the prototype from msdn.microsoft.com for WSARecvFrom is different than that in the NI WindowsSockets:PlatformSDK help file, so I switched to the NI version.
Now I am having troubles with LPWSABUF DataBuf
after delcaring
char FAR RecvBuf[1024];
u_long BufLen = 1024;
the compiler complains at the lines,
DataBuf.len = BufLen;
DataBuf.buf = RecvBuf;
that the Left operand of . has incompatible type LPWSABUF
Now what?
06-30-2006 02:18 PM
I would have thought that DataBuf would have been of type WSABUF. The LPWSABUF type is a pointer to a WSABUF structure. How is DataBuf declared?
07-06-2006 10:50 AM