I have a strange problem as Socket.Select() doesn't block when I call it in
C#. To be sure that there is no error in my code I went to
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fsystemnetsocketssocketclassselecttopic.asp
and copied the sample C# code into VS 2004. When I run the sample code
Socket.Select() does not block?! It returns immediately with an empty IList.
Can anyone please compile and run the following code? I don't understand why
Socket.Select() does not block on my machine? Is Socket.Select() broken or
my .NET framework?
----------------------------
using System;
using System.Collections;
using System.Net;
using System.Net.Sockets;
class SelectTest
{
static void Main(string[] args)
{
Socket mySocket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
mySocket.Bind(new IPEndPoint(IPAddress.Any, 12345));
mySocket.Listen(1);
ArrayList list = new ArrayList();
list.Add(mySocket);
Socket.Select(list, null, null, 1000000);
}
}
----------------------------
TIA,
Boris
Jon Skeet [C# MVP] - 31 May 2004 08:00 GMT
> I have a strange problem as Socket.Select() doesn't block when I call it in
> C#. To be sure that there is no error in my code I went to
[quoted text clipped - 6 lines]
> Socket.Select() does not block on my machine? Is Socket.Select() broken or
> my .NET framework?
When you say it returns "immediately", how immediately do you mean? On
my box the same program blocks for a second before returning - exactly
as I'd expect with a wait time of 1000000 microseconds.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Boris - 31 May 2004 13:33 GMT
> [...]
> When you say it returns "immediately", how immediately do you mean? On
> my box the same program blocks for a second before returning - exactly
> as I'd expect with a wait time of 1000000 microseconds.
I guess it would be a good idea to go to bed earlier and not to program at 2
am ... Thanks for your help and sorry for the confusion but I read
milliseconds and not microseconds in the documentation ... oh well ...
Boris