Hi,
I am trying to get the following behaviour for my Socket connection:
(1) Attempt a blocked read for a defined amount of time.
(2) If a timeout occurs, because no data has been sent to the socket,
throw an exception.
(3) Catch the exception and either go back to (1) or quit reading,
depending on a variety of (user defined) factors.
To implement the above I use:
socket.SetSocketOption(
SocketOptionLevel.Socket,
SocketOptionName.ReceiveTimeout,
timeout);
Everything works as expected until the first timeout occurs. When
try to read again after the first timeout, the next exception occurs
immediately, without respecting the timeout setting.
I get a System.IO.IOException with the following Message:
"Unable to read data from the transport connection: A non-blocking
socket operation could not be completed immediately."
Even after I send data to the socket and successfully read data, the
behaviour of throwing an exception immediately when no data is
avaialble does not go away and I never get the socket back to a
state where it obeys the timeout in the read operation.
What am I missing?
Is there some kind of reset button that I can push on a timeout?