I have exported my application to Android and I am doing UDP broadcasts - it works properly inside the simulator but when I make my Android build and put it on my phone - it does not broadcast and it shows the IP address of the phone as 172.x.x.x rather than 192.xxx.x.x inside my Corona app. I am using the android debugger to find this out - is there any way to get the IP of the android device?? Thanks
Do you have some sort of proxy or firewall on your device? 172 and 192 are both (together with 10.x) internal ip addresses. If your home network is 192. and your phone has an ip of 172 (while not connected to the data network) then you have some sort of proxy, firewall, vpn service running on your phone.
This might be helpful, it’ll give you the device IP internally. Also included a second function that may be useful in the future. It grabs the network information as seen externally from https://ipinfo.io/. You can add the data to a text object so you can see them on the screen.
local json = require("json")
local socket = require("socket")
local function getIP()
local udpSock = socket.udp() --creates a UDP object
udpSock:setpeername( "8.8.8.8", 80 ) -- Attemp connecting to Google Public DNS Server
local ip, sock = udpSock:getsockname()-- get socket from UDP connection
udpSock:close()
print(ip)
end
local function getExternalInfo()
local function networkListener( event )
if ( event.isError ) then
print( "Network error: " .. event.response)
else
--[[
Sample data from response
ip: "49.145.195.159"
hostname: "dsl.49.145.195.159.pldt.net"
city: "Lacson"
region: "Davao"
country: "PH"
loc: "7.2119,125.4422"
org: "AS9299 Philippine Long Distance Telephone Company"
postal: "7010"
timezone: "Asia/Manila"
readme: "https://ipinfo.io/missingauth"
]]
if ( event.phase == "ended" ) then
local info = event.response
local data, message = json.decode(info)
print("External IP: " .. data.ip)
end
end
end
local params = {}
-- Tell network.request() that we want the "began" and "progress" events:
params.progress = "download"
-- get connection client info externally:
network.request( "https://ipinfo.io/json", "GET", networkListener, params )
end
getIP()
getExternalInfo()
This is very cool. I will use it, but I don’t know if they are looking for the external ip. They seem to be concerned with the internal IP
Yup, for local network devices you’ll definitely want to use LAN IP.
Yep figured it out - it was using a private DNS service. But despite that, I still cannot receive a UDP broadcast on the android phone whereas I can inside the corona simulator and on the windows build. How come that is the case the app behaves differently in Android than in windows
Don’t know the answer to your question, but have you by any chance tried this plugin?