Sign in to follow this  
bower12345

Messages not getting sent...

Recommended Posts

bower12345    122
Hey Folks, Does Winsock guarantee that when the send command is made that the entire message will get there? Lets say I am sending the message "mike" from one machine to another. Sometimes I receive the word "mike" and sometimes I receive nothing at all. Do I to use the return value of send in order to make sure that the message got sent? Regards, Mike

Share this post


Link to post
Share on other sites
JonStelly    127
The short answer is:

No


The return value from send() is the number of bytes sent but they haven't been acked yet(if you're talking about TCP) so it's possible they get lost in transmission or the remote host (or a route between you and it) goes down before the data is received, the data never gets there. With TCP any packet lost in transmission will be resent until acknowledged, since UDP isn't reliable you'll need to develop your own ack system if you want to guarantee the data arrives using UDP.

Share this post


Link to post
Share on other sites
bower12345    122
Thanks for the reply. I still find it odd why sometimes the server will receive the data sent and other times it won't receive anything. Basically I'm doing simple user and password authentication with sockets and sometimes the server receives the info and sometimes it doesn't.

Share this post


Link to post
Share on other sites
bower12345    122
I'm using stream socket. I've checked the client program to make sure its actually sending the data I want and it is. I'm doing user authentication within the FD_ACCEPT call. Is this a good idea or should I just use accepting the connection and logging it to the FD_ACCEPT message and using FD_READ to do user authentication? After a socket is connected does it automatically use the FD_READ message, or only after I explicitly call WSAAsyncSelect on that client socket?

Regards,
Mike

Share this post


Link to post
Share on other sites
cbenoi1    484
With TCP, sometimes data is stuck in output buffers for a little while because the TCP algorithm tries to coalesce as much data as possible to make 576 bytes (+/-) packet sizes. You can turn this off using this call:

setsockopt( ..., TCP_NODELAY, ... );

Here is what the docs says:

The TCP_NODELAY option is specific to TCP/IP service providers. The Nagle algorithm is disabled if the TCP_NODELAY option is enabled (and vice versa). The process involves buffering send data when there is unacknowledged data already in flight or buffering send data until a full-size packet can be sent. It is highly recommended that TCP/IP service providers enable the Nagle Algorithm by default, and for the vast majority of application protocols the Nagle Algorithm can deliver significant performance enhancements. However, for some applications this algorithm can impede performance, and TCP_NODELAY can be used to turn it off. These are applications where many small messages are sent, and the time delays between the messages are maintained. Application writers should not set TCP_NODELAY unless the impact of doing so is well-understood and desired because setting TCP_NODELAY can have a significant negative impact on network and application performance.


Hope this helps.

-cb

Share this post


Link to post
Share on other sites
bower12345    122
Ok I tried this:


bOptVal = true;
nbOptVal = sizeof( bool );
if( setsockopt( hSocket, IPPROTO_TCP, TCP_NODELAY, (char *)&bOptVal, nbOptVal ) == SOCKET_ERROR )
MessageBox( NULL, "Error Setting Socket Options", "Error", MB_OK );


Does this seem right or am I setting the socket options wrong? No error occurs when I make the call to the function. I am still having the problem when the information is being sent to the server that the server does not receive anything. Please advise.

Regards,
Mike

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this