Android的:如何检查服务器是否可用? [英] Android: How to check if the server is available?

查看:741
本文介绍了Android的:如何检查服务器是否可用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在开发的连接到服务器的应用程序。现在登录和数据传输工作正常,如果theserver可用。当服务器不可用时,问题就出现了。在这种情况下,该方法发送一个登录请求,并等待响应。

有谁知道如何检查服务器是否可用(可视)?

简单的逻辑是,必须实现的伪code是如下:

  1. 字符串serverAddress =(从配置文件中读取值)//已完成
  2. 在布尔serverAvailable =(检查服务器serveraddress为提供)//已得到执行
  3. (下面是取决于serverAvailable逻辑)
解决方案

他可能需要的Java code,因为他的工作在Android上。 Java的等价物 - 我相信在Android上的作品 - 应该是:

  InetAddress.getByName(主机).isReachable(超时)
 

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)

解决方案

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)

这篇关于Android的:如何检查服务器是否可用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆