Internet access

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
anmldr
Posts: 459
Joined: Tue Sep 11, 2012 11:13 pm

Internet access

Post by anmldr » Mon Aug 16, 2021 2:33 am

I now live in Costa Rica. Internet access is frequently unavailable at my house...many places in Costa Rica, really. It is on-off-on frequently. Is there a command or function in LC that can check the status of a connection while the app is running in the background? This would be for all platforms. This way I would not need to constantly check on it myself. I could be doing other tasks that do not require access and be alerted when the Internet is available again.

Thanks,
Linda

andresdt
Posts: 146
Joined: Fri Aug 16, 2019 7:51 pm

Re: Internet access

Post by andresdt » Mon Aug 16, 2021 3:53 am

There are things I don't know how to do, for example make the app run as a background system service. I know that in Win it is possible and that in Android it is not. In the rest of the platforms I have no idea. But here I share something that can help you.

Code: Select all

on mouseUp
    __InternetMonitor
end mouseUp 

constant kURL = "http://detectportal.firefox.com/"
command __InternetMonitor
    unload URL kURL
    load URL kURL with message "InternetStatus"
end __InternetMonitor

local sLastStatus
on InternetStatus pURL, pStatus
    if pURL is kURL then
        if pStatus is not "cached" then
            put pStatus into sLastStatus
            -- Not Internet
        else
            if sLastStatus is no pStatus then
                put pStatus into sLastStatus
                put url pURL
                beep
                -- Launch App or URL
                answer warning "Internet"
            end if
        end if
    end if
    
    send "__InternetMonitor" to me in 1 sec
end InternetStatus


Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”