Android Question Ping web without waiting

Rizal Putra

Member
Licensed User
Longtime User
How to ping website without waiting for a response ?


I use ping as background service, sample code in Ping Service module :
B4X:
    Dim SB As StringBuilder
    SB.Initialize
   
    PH.Shell("ping -c 1 www.google.com"),Null,SB,Null)
   
    If SB.ToString="" Then
        StatusPing="Failed"
    Else
        StatusPing="Success"
    End If


In Main module, i use this code to start Ping service :
B4X:
        StartService(PingService)


The problem is when start Ping service, Main module is freezing because waiting response for Ping service.
 

DonManfred

Expert
Licensed User
Longtime User
Surely the whole point of Ping is to get a response.. What are you trying to achieve here?

Getting a response in 0ms? ;)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
Dim job As HttpJob
job.Initialize("ping", Me)
job.Download("http://www.vdfb.de/b4a/ping.php")


Sub JobDone(job As HttpJob)
    If job.Success Then
      If job.JobName = "ping" Then
            Dim res As String
        res = job.GetString
            If res = "pong" Then
                ToastMessageShow("Website ONLINE", True)
            End If
        End If
  Else
      Log("Error: " & job.ErrorMessage)
  End If
  job.Release
End Sub

You can use the ping-script (http://www.vdfb.de/b4a/ping.php) in your project if you want
 
Upvote 0
Top