Checking connection to server?

This used to work on the Mac simulator. Now, it always fails (I have put a simulator check in the following code) when I test for access to my server (not apple or google!)

Why? The examples indicate it should work just fine…and I got it from an example!

-------------------------------------------------------- -- canConnectWithServer: return true if connected, false if not. -- url: a server to check (use http://...) -- showActivity: Turn off the activity indicator (must be turned on before starting) -------------------------------------------------------- function canConnectWithServer(url, callback) local function MyNetworkReachabilityListener(event) local testing = true if (testing) then print( "url", url ) print( "address", event.address ) print( "isReachable", event.isReachable ) print("isConnectionRequired", event.isConnectionRequired) print("isConnectionOnDemand", event.isConnectionOnDemand) print("IsInteractionRequired", event.isInteractionRequired) print("IsReachableViaCellular", event.isReachableViaCellular) print("IsReachableViaWiFi", event.isReachableViaWiFi) print("removing event listener") end network.setStatusListener( url, nil) -- Simulator bug or something...always returns failure local isSimulator = "simulator" == system.getInfo("environment") if (isSimulator) then event.isReachable = true print ("canConnectWithServer: Corona simulator: return TRUE for event.isReachable") end if (type(callback) ~= "function") then return event.isReachable else callback(event.isReachable) end end if network.canDetectNetworkStatusChanges then network.setStatusListener( url, MyNetworkReachabilityListener ) else print("funx.canConnectWithServer: network reachability not supported on this platform") end end

I haven’t tested your entire code but I noticed that on line 25 it’s better this way:

    local isSimulator = system.getInfo(“environment”) and “simulator” or “not simulator”

    print("System info " … isSimulator)

I hope this helps!

Leonardo

I haven’t tested your entire code but I noticed that on line 25 it’s better this way:

    local isSimulator = system.getInfo(“environment”) and “simulator” or “not simulator”

    print("System info " … isSimulator)

I hope this helps!

Leonardo