Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to check if the server is available?

I am developing an application which connects to the server. By now the login and data transmission works fine if theserver is available. The problem arises when the server is unavailable. In this case the method sends a login request and waits for the response.

Does anyone know how to check if the server is available (visible)?

The pseudocode of the simple logic that has to be implemented is the following:

  1. String serverAddress = (Read value from configuration file) //already done
  2. boolean serverAvailable = (Check if the server serverAddress is available)//has to be implemented
  3. (Here comes the logic which depends on serverAvailable)
like image 238
Niko Gamulin Avatar asked Sep 18 '09 08:09

Niko Gamulin


People also ask

How do you check if a service is running or not Android?

You can do this by making your own Interface where you declare for example " isServiceRunning() ". You can then bind your Activity to your Service, run the method isServiceRunning(), the Service will check for itself if it is running or not and returns a boolean to your Activity.

What is a server in Android?

In reality, a server is any computer designed to handle requests for information or files. Almost any computer can be converted to run as a server, and this includes Android devices. Even an old iPhone or iPad can be jailbroken and made into a server, but we'll save that for another guide.

What is server side in Android app?

Most mobile apps have two parts: client and server. The client side is the app that runs on your device, while the server-side code runs on a remote server. Although the focus of this class is on the client side, we do want students to be able to write some simple server-side code.


1 Answers

He probably needs Java code since he's working on Android. The Java equivalent -- which I believe works on Android -- should be:

InetAddress.getByName(host).isReachable(timeOut) 
like image 188
Sean Owen Avatar answered Sep 21 '22 12:09

Sean Owen