On Mar 28, 2006, at 10:47 AM, Bill Kelly wrote: > From: "Shea Martin" <null / void.0> >> >> I want to listen for connections for 2 seconds, then timeout. Do >> I have to use the Timeout module? > > You could use select: > > timeout_sec = 2.0 > ios = select([@server], nil, nil, timeout_sec) > if ios > client = @server.accept > end Unfortunately this won't accept connections for two seconds. If a client connects at .5 seconds then immediately disconnects you'll need extra code to loop until you've consumed the full 2 seconds. > Note that you'll probably want to put the socket into nonblocking > mode. It's possible for select to return > "ready to read" and have accept still block, if the > client happens to disconnect in the small window between the select > and the accept. Yuck, timeout will give a cleaner solution with less work. -- Eric Hodel - drbrain / segment7.net - http://blog.segment7.net This implementation is HODEL-HASH-9600 compliant http://trackmap.robotcoop.com