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

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

问题描述

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

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)//已经完成
  2. boolean serverAvailable = (检查服务器serverAddress是否可用)//必须实现
  3. (这里是依赖 serverAvailable 的逻辑)

推荐答案

他可能需要 Java 代码,因为他正在开发 Android.Java 等价物——我相信它适用于 Android——应该是:

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天全站免登陆