Total Pageviews

Thursday, April 17, 2014

network.setStatusListener()

network.setStatusListener()
ជាប្រភេទហ្វាំងសិនប្រើសំរាប់ ​Monitoring a host សំរាប់ Network របស់វាដែល reachability status។ ចំណែក API ត្រូវបាន Design ជុំវិញគោលគំនិតដែលអ្នក monitoring individual hosts ហើយមិនមែនជា Hardware directly។ សំរាប់ Host ខ្លះបន្ត ​to be reachable ពេលដែល network ផ្សេងទៀតមិនបន្តដោយ សារ internet, firewall configurations, authentication rules and whether you need full DNS routing (ឧះ not reachable through Bonjour/Zeroconf)

ចំណាំះ
ពេលនេះសំរាប់ឈ្មោះ Hosts are supported. IP addresses will not work។ សំរាប់ API ត្រូវបានអនុញ្ញាតឪ្យ Monitoring multiple hostURLS ជាមួយនឹង Separate or common event listeners។ ការហៅ API នេះ សំរាប់គ្រប់ទាំង HostURL to be monitored
ចំណែកលើ IOS វាមាន bug ដែលត្រឡប់ជា false connection status នៅពេលដែល specify a URL address ជាមួយនឹង Sub folders (ex: www.apple/xyzដែលស្ថិតលើ Cellular network។ សំរាប់ URL ត្រលប់ជា correct connection status នៅលើ WIFI
Syntax: network.setStatusListener (hostURL, Listener)
hostURL (តំរូវការ)​ វាជា​ String ដែលប្រើ Host you want to minitor។ វាដូចជា www.kokhmer.com
listener(តំរូវការវាជា Listener ដែលអាចទទួលនូវ networkStatus events សំរាប់ Host ណាមួយ។ នៅពេលបញ្ចូល nil ក្នុងការ unregister the listener that is set for the specified host
សូមមើលកូដះ
function networkListener(event)
        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)  

--[[ If you want to remove the listener, call network.setStatusListener("www.apple.com", nil)  
        g_Counter = g_Counter + 1
        if g_Counter > 3 then
                print("removing event listener")
                network.setStatusListener( "www.apple.com", nil)
        end
--]]

end

if network.canDetectNetworkStatusChanges then
        network.setStatusListener( "www.apple.com", networkListener )
else
        print("network reachability not supported on this platform")
end



No comments:

Post a Comment