Android Code Snippet [B4X] B4XPing: ping to server

Ping a server to indicate whether it is up or down, or if it is a valid server.
B4X:
    Dim Ping As B4XPing
    Ping.Initialize
   
    Ping.TimeOut = 30 * DateTime.TicksPerSecond 'default 60 seconds
    Ping.ListPorts = CreateMap("http":80, "https":443) 'default "http":80, "https":443, "ftp":21
    Ping.DefaultPort = 443 'Default 80
   
    Log("********** URL True **********")
    Dim URL As String = "https://translate.google.com/?sl=auto&tl=es&op=translate"
    Wait For (Ping.Server(URL)) Complete (Result As Boolean)
    Log(URL)
    Log(Result)
 
    Dim URL As String = "b4x.com" 'DefaultPort
    Wait For (Ping.Server(URL)) Complete (Result As Boolean)
    Log(URL)
    Log(Result)
   
    Log("********** URL False **********")
   
    Dim URL As String = "https://translate.googlexxxx.com/?sl=auto&tl=es&op=translate"
    Wait For (Ping.Server(URL)) Complete (Result As Boolean)
    Log(URL)
    Log(Result)
 
    Dim URL As String ="b4xxxx.com" 'DefaultPort
    Wait For (Ping.Server(URL)) Complete (Result As Boolean)
    Log(URL)
    Log(Result)
1725603938654.png


Regards.
 
Last edited:

josejad

Expert
Licensed User
Longtime User
Thanks for sharing.
Just to clarify, I think you're missed the code snippet from your post


B4X:
Public Sub Ping(Host As String, Port As Int) As ResumableSub
    Dim Socket As Socket
    Try
        Socket.Initialize("Socket")
        Socket.Connect(Host, Port, 60 * DateTime.TicksPerSecond)
        Wait For Socket_Connected (Successful As Boolean)
    Catch
        Log(LastException)
    End Try
    Return Successful
End Sub
 

TILogistic

Expert
Licensed User
Longtime User
Thanks for sharing.
Just to clarify, I think you're missed the code snippet from your post


B4X:
Public Sub Ping(Host As String, Port As Int) As ResumableSub
    Dim Socket As Socket
    Try
        Socket.Initialize("Socket")
        Socket.Connect(Host, Port, 60 * DateTime.TicksPerSecond)
        Wait For Socket_Connected (Successful As Boolean)
    Catch
        Log(LastException)
    End Try
    Return Successful
End Sub
Yes, it is one of the routines I use in the B4XPing class.
and others with javaobject.
 

TILogistic

Expert
Licensed User
Longtime User
and I also posted it here.

My friend Jose, greetings
Oparra.
 
Last edited:
Top