I use a tcp socket in the following way:
m_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); m_socket.ReceiveTimeout = 15;
The general flow is that I run the m_socket.Receive in an infinite while loop and at some point the socket becomes empty for a long period but I don't want to close it. Instead I want to keep trying to read and timeout with exception every 15 seconds.
What happens is that in the first time the socket becomes empty I get a timeout socket exception after 15 seconds as expected. Then, because I'm still in the loop, m_socket.Receive is called again - however this time a non-blocking socket operation could not be completed exception is thrown (which is not what I expect, it supposes to block for another 15 seconds) even though when I query m_socket.Blocking one line above, it says TRUE.
The interesting thing is that if I perform m_socket.Blocking = true; just before m_socket.Receive, everything runs as expected (only timeout exceptions are thrown every 15 seconds).
The only possible explanation is that the timeout exception somehow changed the Receive operation or the Socket operations in general to work in a non-blocking way while not changing the "Blocking" property accordingly.