Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / May 2004

Tip: Looking for answers? Try searching our database.

Socket.Select() does not block???

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Boris - 31 May 2004 01:17 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
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.