According to MSDN documentation it is not possible to set Socket.SendTimeout to a value less than 500ms: http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.sendtimeout Same rule is valid for Socket.ReceiveTimeout (even it is not mentioned in MSDN documentation, this is true, as both cases were tested practically).
Are there any other ways to timeout a socket receive operation if it, for example, takes longer than 10ms to complete?
The simple answer is “you don’t”.
Send()andReceive()calls block the flow of the program until data was sent, received or an error occurred.If you want to have more control over your calls, there are several mechanisms available. The simplest is to use
Poll().You can also use
Select(),BeginReceive()orReceiveAsync()for other types of behaviors.I recommend you read Stevens’ UNIX Network Programming chapters 6 and 16 for more in-depth information on non-blocking socket usage. Even though the book has UNIX in its name, the overall sockets architecture is essentially the same in UNIX and Windows (and .net)