How to ping the server in android?

by hal.littel , in category: Third Party Scripts , 6 months ago

How to ping the server in android?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by daisha , 6 months ago

@hal.littel 

To ping a server in an Android device, you can use the following code snippet:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.io.IOException;

public boolean isServerReachable() {
    try {
        InetAddress address = InetAddress.getByName("your_server_address_here");
        // Timeout in milliseconds
        if (address.isReachable(5000)) {
            return true;
        }
    } catch (UnknownHostException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return false;
}


You can call the isServerReachable function to check if the server is reachable from the Android device. Be sure to replace "your_server_address_here" with the actual address of the server you want to ping.

Related Threads:

How to ping the mysql server in yii2 framework?
How to get the time in ping?
How to download file in android over https?
How to send json object to android in codeigniter?
How to build an android studio project cloned from git?
How to change the teradata server port number?