views:

445

answers:

1

I have an app that connects to a host that might be down. If the host is down I don't want to wait for the 30 or so seconds it takes to time out. I'm using blocking sockets at the moment.

I've been looking at socket.poll() and socket.select() but I'd rather just have a time setting on the socket. I don't mind if it's a setting I have to do somewhere in the system. Also, I seemed to understand that poll and select don't work with connection oriented communication -is this correct?

If this is absolutely impossible, what is a nice way to get the results I want using poll, select or some other technique?

+2  A: 

See BeginConnect and Asynchronous Programming Overview

IAsyncResult asr = socket.BeginConnect( ip, port, null, null );

bool res = asr.AsyncWaitHandle.WaitOne( 10000, true );  // 10 sec timeout

Update: There is a better example here.

Ed Guiness