Corona cannot resolve LAN hostnames anymore

Hi, apparently the newer versions of Corona have lost the ability to resolve hostnames with luasocket? This is causing problems for us, as we have updated one of our apps made with Corona for 64bit iOS11 and now even the Corona Simulator won’t resolve the hostnames (on the same machines that will otherwise resolve them in other applications).

Please show the code you use to do this here and we’ll see if anyone has advice.

local socket = require( "socket" ) function getServerIp() local s = socket.udp() s:settimeout(2500) s:setpeername( "hostname", 0 ) local ip, \_ = s:getsockname() print( "hostname", ip, \_ ) if ip and ip ~= "0.0.0.0" then return ip end return nil end

An example using getsockname to get the IP address of a device through it’s netbios hostname on the network. To use, change the hostname string to the hostname of a device on your local network.

I recommend trying to do a ping it by it’s hostname first, because if that should work, this should work, but as far as I know, this doesn’t work in Corona anymore (neither simulator nor iOS device), and I can’t pinpoint when this change was made due to not needing to update our app since we’ve made it.

What happens is that getsockname should output the IP address of whatever device you set in setpeername(), but as you can see, no matter what you put, it returns “0.0.0.0”.

You might find this forum thread helpful: https://forums.coronalabs.com/topic/63788-autolan-ipv6/

Rob

You should not use ZERO port number, it’s reserved by OSX

Just change ‘0’ in

s:setpeername( “hostname”, 0 )

to something else, for example

s:setpeername( “hostname”, 1 )

Tested, works for me

Please show the code you use to do this here and we’ll see if anyone has advice.

local socket = require( "socket" ) function getServerIp() local s = socket.udp() s:settimeout(2500) s:setpeername( "hostname", 0 ) local ip, \_ = s:getsockname() print( "hostname", ip, \_ ) if ip and ip ~= "0.0.0.0" then return ip end return nil end

An example using getsockname to get the IP address of a device through it’s netbios hostname on the network. To use, change the hostname string to the hostname of a device on your local network.

I recommend trying to do a ping it by it’s hostname first, because if that should work, this should work, but as far as I know, this doesn’t work in Corona anymore (neither simulator nor iOS device), and I can’t pinpoint when this change was made due to not needing to update our app since we’ve made it.

What happens is that getsockname should output the IP address of whatever device you set in setpeername(), but as you can see, no matter what you put, it returns “0.0.0.0”.

You might find this forum thread helpful: https://forums.coronalabs.com/topic/63788-autolan-ipv6/

Rob

You should not use ZERO port number, it’s reserved by OSX

Just change ‘0’ in

s:setpeername( “hostname”, 0 )

to something else, for example

s:setpeername( “hostname”, 1 )

Tested, works for me