Last active
August 29, 2015 14:01
-
-
Save minsOne/085c95bba0c130a40ef1 to your computer and use it in GitHub Desktop.
Checking Connected Network Method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
네트워크 동작 여부 확인 메소드 | |
결과값이 true이면 네트워크가 연결된 상태이며 false인 경우 네트워크가 연결되지 않은 상태이다. | |
]]-- | |
function networkController:networkReachabilityListener() | |
local io = require("io") | |
local http = require("socket.http") | |
local count = 0; | |
local function networkListener() | |
local io = require("io") | |
local http = require("socket.http") | |
local b, c, h = http.request("http://google.com") | |
local code | |
if (c == "host not found") then | |
code = 404 | |
else | |
code = tonumber( c ); | |
end | |
print( "Code : ", code ) | |
if ( code and (code / 100) == 2) then | |
return true; | |
else | |
return false; | |
end | |
end | |
local function checkCount() | |
local result = networkListener(); | |
if (result) then | |
return result; | |
else | |
if (count < 3) then | |
count = count + 1; | |
return checkCount(); | |
else | |
return false; | |
end | |
end | |
end | |
local result = checkCount(); | |
return result; | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment