Sign in to follow this  

pleading for winsock help

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

Heya all, This is the first time I've worked with winsock and I'm begging for some help (and I HAVE read many tutorials). There's something I'm not getting. Basically, I have a console that runs the server and a windows app for the client. When the client connects, the server sends a series of messages (test messages, for now). Currently, only one or two of the messages is recieved by the client correctly. However, if I put a small delay, say 100 ms, between send()'s from the server, the messages get through fine. My theory is there is some WSAEWOULDBLOCK issue, but everything I have tried hasn't worked. If someone could tell me how to post code, I can put it up here or I can put it up on my website. Thanks much!

Share this post


Link to post
Share on other sites
When sending you have to check to see how many bytes were actually sent. Its possible that the kernel is only sending half your message without the delay and you're expecting the whole message to go through.

When using winsock you have to check all output paramters and return values.

If you click the 'faq' link it will walk you through various mockup codes. Heres a link to the faq.

Share this post


Link to post
Share on other sites
Also another tip, don't use non-blocking sockets. They're not worth the confusion. Instead use the select function to detect when data is waiting for you on a socket.

If you want I can walk you through how to use select for a completely non-blocking networking app without using the dumb and confusing EALONGMACROFORNONBLOCKING stuff.

Share this post


Link to post
Share on other sites
Quote:
Original post by argonaut
Basically, I have a console that runs the server and a windows app for the client. When the client connects, the server sends a series of messages (test messages, for now). Currently, only one or two of the messages is recieved by the client correctly. However, if I put a small delay, say 100 ms, between send()'s from the server, the messages get through fine.


Q14 of the FAQ reminds us that if you send() twice in TCP, you're very likely to receive them both with the same one recv() call. Are you checking to see how much data you're receiving? TCP acts like a stream, whereas UDP acts as datagrams.

To give you an example, if I called send() with a 5 byte packet, then a 4 byte packet, then a 10 byte packet, I might get 19 bytes back with one recv() call, or I might get 19 1 byte packets, or anything in between. TCP will usually wait a little while before sending data out to see if you're going to tack on more, which could easily cause exactly the behavior you're describing.

Apologies if this isn't your problem.

Share this post


Link to post
Share on other sites
Oh and I ran some tests on windows XP (but i assume its the same for earlier versions) on the select function. There were some beliefs that it had a minimium 10 millisecond delay for every function call, and therefore you should only use it by passing *all* of your sockets to it at once.

The tests I ran concluded that for about 99.99% of the time the function returns near immediately and in some rare cases (it was about 2-4 in a couple hundred thousand) it would stall for 1-3 milliseconds.

So therefore I would just make a wrapper function that takes a socket, runs select on that socket, and returns true if the socket is ready to recieve data. I've implemented the function a number of times. You end up with code like this:


if(isSocketReady(sock))
recv(socket, ...);





And its completely non-blocking and very simple and very straight forward.

Share this post


Link to post
Share on other sites

This topic is 4106 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.

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