I am trying to perform a relatively basic TCP socket send / receive operation in Windows CE using the .NET Compact Framework. I am trying to set a timeout value to read / write a slow connection timeout, rather than blocking forever. The overall structure I can just set the properties ReceiveTimeoutand SendTimeoutthe object Socket. Unfortunately, setting these properties on a compact frame immediately raises a SocketException about using an unsupported socket option.
After digging a bit further, I came across this page , which says the following:
The following table shows BSD options not supported for setsockopt:
Value Type Description
SO_ACCEPTCONN BOOL Sets socket listening.
SO_RCVLOWAT int Sets recv low watermark.
SO_RCVTIMEO int Sets time-out for recv.
SO_SNDLOWAT int Sets send low watermark.
SO_SNDTIMEO int Sets time-out value for send.
SO_TYPE int Sets socket type.
Thus, it does not look like Windows CE supports timeouts. The timeout will eventually occur with a non-responsive connection, but it seems to take about a minute (should be hardcoded somewhere in WinCE). So now I'm trying to figure out how to implement this manually. My first thought is to use asynchronous I / O, which allows me WaitOne(timeout). However, this will not stop the asynchronous thread, which will depend on EndSend()orEndReceive(). That way, even if I can skip my main thread, threads will still occur until a hard-coded timeout is reached. During this time, my application will not be closed. The only way I can solve this problem is to interrupt the asynchronous thread, but this seems like a very bad idea, and I would like to avoid it.
So what is the right way to handle this? There should be an easy way, since other applications (like IE on WinCE) do not seem to have problems with timeout or canceling pending network operations, and they seem to also be able to shut down without problems.
Jason source
share