title: Lua set timeout for connect
body: <p>Looks like <a href="http://w3.impa.br/~diego/software/luasocket/tcp.html#settimeout" rel="nofollow">setting timeout</a> for Lua socket only works after <code>connect</code>, and I can't use <code>assert (socket.connect (..))</code>, because I have multiple servers to try out.</p>
  
  <p>My scenario is that when one server is down (can't connect rather than unstable network), I will resort to a different one, so I must have a timeout on connect.</p>
  
  <p>Any suggestions?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I found Lua TCP socket, but with that, I was unable to detect connection failure,</p>
  
  <pre><code>local tcp = socket.tcp()
  tcp:settimeout(1)
  tcp:connect(...)
  </code></pre>