Advertisement

Problem with my Nonblocking socket in winsock

Started by May 18, 2005 10:43 AM
1 comment, last by Dark Star 19 years, 9 months ago
Hi Guys, Whenever I set my socket as non blocking by using this function: ioctlsocket(sock,FIONBIO,&data I have noticed that I cannot receive data consistently and sometimes never at all. I would like to know if setting my socket as non blocking creates any issues with sending data or receiving data. Of course I watch out for error return values when using recv() such as whether data was sent or not, by checking for the error WSAEWOULDBLOCK. I assume by the definition in MSDN of WSAEWOULDBLOCK:
Quote:
The socket is marked as nonblocking and the receive operation would block.
to mean that there was no data on the socket at that particular call to recv? Is that correct? Because I respond to that error when I get it and act appropriately. When my socket is set as Blocking however, the socket blocks when Reading from socket as one would expect, but receives everything correctly. By the way Im only having this problem with nonblocking sockets when my friend connects from over the internet to my Server.exe program from my Client.exe program which are DOS based. When Server and Client programs are run on same computer everything is fine even with nonblocking sockets. It's using TCP/IP if you wanted to know. Sorry for long post. I will try to cut it down next time. Hope anyone can help. Tnanks in advance. DarkStar UK
---------------------------------------------You Only Live Once - Don't be afriad to take chances.
A long post with relevant details is better than a short post lacking those details.

Have you started at the Forum FAQ? It describes some problems you may run into when using TCP and non-blocking reads. Specifically, you need to be prepared to get only part of a message at one time, or more than a single message, and you have to buffer and split data as appropriate.

To get a better answer, I believe you have to provide some more information: specifically, what do you send in these cases, and what do you receive? It is true that you'll get the would-block error if there is currently no data on the socket.

Also, when the other end tries to connect to you, are you behind NAT? Are you setting up the right port forwarding? Again, this is mentioned in the Forum FAQ.
enum Bool { True, False, FileNotFound };
Advertisement
Thanks for the reply,

Yes I have looked at the forum before posting. That was quiet useful. As for what I send.Currently Im sending simple numbers and bytes although everything is ultimately transformed into bytes before going down the socket.

I got a protocol which sends 1 byte first to denote the type of data type the NEXT data to be sent will be, so that on the receiving end, it will know how many bytes to read after reading the preliminary 1 byte.

In most cases in my current project, I usually receive nothing down the line.. Or when I do receive data, some data is missed out. Which is sort of strange. I guess Im gonna have to do some more testing to make sure it's not a bug in my own code, but Ive been over it so many times.

Thanks for any help

DarkStar.
UK.

---------------------------------------------You Only Live Once - Don't be afriad to take chances.

This topic is closed to new replies.

Advertisement