Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

networking - 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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...