Archived

This topic is now archived and is closed to further replies.

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

This topic is 5152 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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().

Share this post


Link to post
Share on other sites
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/

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites