Ah, yeah, my bad, that’s the standard pattern for async connect (initiate connect, poll with select() for success or failure, yield’ing along the way). Oops.
So, I temporarily commented out the settimeout(0)
call, and changed that area to the following:
self.sock = socket.tcp()
-- self.sock:settimeout(0)
local status, err = self.sock:connect(host,port)
print("sock:connect", status, err)
and the output was:
DEBUG:SCRIPT: sock:connect nil host or service not provided, or not known
I don’t know what version of luasocket
is bundled in defold-luasocket
but this commit is pretty telling:
Although, I commented out the zero-timeout, so in theory it should try all the addresses, but maybe that was implemented in a commit after the version that’s bundled in defold-luasocket
? The latest luasocket
docs and source (c.f. src/inet.c
) implement a socket.dns
module, but I can’t seem to find that in defold-luasocket
.
As a quick test, I tried hard-coding my IPv6 address in as host
to see if this would successfully connect if I fed it the IPv6 address and didn’t depend on DNS/resolver order… and I managed to get it to work if I changed socket.tcp()
to socket.tcp6()
… but I’m obviously concerned that won’t work if I’m on an IPv4-only network, because I seem to recall seeing that the Lua socket.tcp6()
was implemented to bind IPv6-only mode… otherwise we could just use socket.tcp6()
everywhere and let it gracefully degrade to IPv4 when necessary…