...winsock (UDP) recvfrom error...

Started by
5 comments, last by particleG 20 years, 5 months ago
Whenever I try using the recvfrom in winsock (version 1) function I get the following error. WSAEFAULT The buf or to parameters are not part of the user address space, or the tolen parameter is too small. When I call the function with the last 2 parameters as NULL the thing seems to crash (not respond). Anything that I put into the last 2 parameters causes this error, except NULL. What am I doing wrong? THanks
Advertisement
If it''s not responding, and you''re using blocking sockets, then it probably just means that there''s no data waiting to be read.

But there is data to be read, I am sending it data using the ''sentto'' function. I just can''t receive it.

Btw is there a way to check if data is there to be read if that is the case, I don''t want my application just stopping if the function doesn''t return.


Thanks
You can switch to non-blocking sockets or use select() to check if data is there before reading. And by select() I also mean WSAAsyncSelect().

what are these non-blocking sockets and how do I use them?


any tutorials somewhere, havent been able to find any


Thanks

A non-blocking socket, is essentially a socket where calling functions on it will return immediately. Like if you call recv() and there''s no data in the buffer, it''ll return WSAEWOULDBLOCK, which basically means, "try again later."

To make a socket non-blocking, call ioctlsocket() with FIONBIO as a parameter.

Gamedev has a list a few network programming resources:
http://www.gamedev.net/reference/list.asp?categoryid=30

Another site you might try, that isn''t listed above, is the Winsock Programmer''s FAQ:
http://tangentsoft.net/wskfaq/
quote:Original post by particleG

Whenever I try using the recvfrom in winsock (version 1) function I get the following error.

WSAEFAULT The buf or to parameters are not part of the user address space, or the tolen parameter is too small.



The second to last parameter needs to be a pointer to a sockaddr structure. The last parameter is an in/out parameter - you need to set it before calling the function and the function will change it as necessary (hence it''s a pointer to an int). Make sure you are setting this to the sizeof(sockaddr) before calling the function.






"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan

This topic is closed to new replies.

Advertisement