Reputation: 23489
Looks like setting timeout for Lua socket only works after connect
, and I can't use assert (socket.connect (..))
, because I have multiple servers to try out.
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.
Any suggestions?
EDIT
I found Lua TCP socket, but with that, I was unable to detect connection failure,
local tcp = socket.tcp()
tcp:settimeout(1)
tcp:connect(...)
Upvotes: 1
Views: 4007
Reputation: 7048
If it does not work it is probably because your luasocket is too old, update to version 2:
Starting with LuaSocket 2.0, the settimeout method affects the behavior of connect, causing it to return with an error in case of a timeout.
(source: http://w3.impa.br/~diego/software/luasocket/tcp.html#connect)
Upvotes: 5