Jump to content
  • Advertisement
Sign in to follow this  
tmarques4

buffer size

This topic is 3591 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

hi everybody!! i'm trying to understand some errors on my app... it sends a message on a buffer of size [200000] to a server that receives the exact message.... it works fine on some computers but other computers just receives an empty message and then if i use a smaller size like [2000] it receives the message... i'm wondering if a size limit varies from a computer to another and how i can find this value.... thanks for the help.... //Client code send(socket, "HUM", 200000, NULL); //Server code recv(socket, buffer_online, 200000, NULL);

Share this post


Link to post
Share on other sites
Advertisement
What do send() and recv() return? There's an internal buffer in the WinSock library which can get filled up. When that happens, send() will return a value < 200000.

Are you using blocking or non-blocking sockets, and are you using UDP or TCP/IP?

Share this post


Link to post
Share on other sites
send()

Quote:
The maximum message packet size for a provider can be obtained by calling getsockopt with the optname parameter set to SO_MAX_MSG_SIZE to retrieve the value of socket option. If the data is too long to pass atomically through the underlying protocol, the error WSAEMSGSIZE is returned, and no data is transmitted.




Quote:
send(socket, "HUM", 200000, NULL);
This is a very nice buffer overrun. Length in this case is 4.

Share this post


Link to post
Share on other sites
my app doesnt retrieve the value returned by send, should i use this value on te recv, like a header??
they are blocking tcp sockets, i also use SOCKET_STREAM...

Share this post


Link to post
Share on other sites
Quote:
Original post by tmarques4
my app doesnt retrieve the value returned by send, should i use this value on te recv, like a header??
they are blocking tcp sockets, i also use SOCKET_STREAM...
Not checking return values is a very good way to get a crash in the best case, and unexpected behaviour in the worst case.

From the Documentation:
Quote:
Return Value
If no error occurs, send returns the total number of bytes sent, which can be less than the number requested to be sent in the len parameter. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError.
I suspect that send() is failing because the buffer is too large. 200KB is a massive amount to try and send in one try - you could try breaking that down into smaller chunks (Definitely no more than 64KB, I'd even be hesitant at sending 4KB).

Share this post


Link to post
Share on other sites
i dont use "hum", its an example... what it really does is send a 2mb txt file on 10 packages... i noticed that the getsockopt() is used for datagram sockets on that thread... it returns NULL when using stream sockets... is there other way to do this on stream?? thanks...

Share this post


Link to post
Share on other sites
can i call send() 100 times to send the whole file without missing any package?? is this the best way to send a large file??

Share this post


Link to post
Share on other sites
Quote:
Original post by tmarques4
can i call send() 100 times to send the whole file without missing any package?? is this the best way to send a large file??


The "best" way is to send some fixed amount (2-64k is a nice number). send() will then report how much went through, or what went wrong. This is enough to know what to send next.

Share this post


Link to post
Share on other sites
Note that calling recv(), even if it is blocking, will only block if there is NO data in the buffer. If there is at least one byte, it will return what's in the buffer or the recv() buffer size, whichever is *SMALLER*. The POSIX read() system call will "try harder" to fill the buffer, until the socket is actually closed, but you can't use POSIX read() on Windows.

Let me repeat that again: Even if a socket is blocking, calling recv() on that socket WILL NOT BLOCK if there is AT LEAST ONE BYTE to be returned.

Share this post


Link to post
Share on other sites
i changed the whole code today it took me a while but it finally seems to be working without errors or deadlocks... im using size = 2000 now and im retrieving information on bytes sent to detect errors... think i understand this network thing now... thanks everybody for the help... happy new year!!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!