android连接webservice,怎么判断是否连通可用

本人新手,刚学android,做一个移动设备,设备需要连接服务器,需要设置移动设备
上的ip和端口,先在问题是用户用移动端设置了ip和端口,怎么检测用户已经设置正确,
并且能够访问webservice呢?

http请求,如何返回的是http错误码,根据错误码判断是什么状况

 TextView info = (TextView) findViewById(R.id.info); 
 InetAddress in;

        in = null;
        // Definimos la ip de la cual haremos el ping
        try {
            in = InetAddress.getByName("你要连接的机器ip");
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        // Definimos un tiempo en el cual ha de responder
        try {
            if (in.isReachable(5000)) {
                info.setText("Responde OK");
            } else {
                info.setText("No responde: Time out");
            }
       } catch (IOException e) {
            // TODO Auto-generated catch block
            info.setText(e.toString());
        }

或者这个。

 private boolean executeCommand(){
        System.out.println("executeCommand");
        Runtime runtime = Runtime.getRuntime();
        try
        {
            Process  mIpAddrProcess = runtime.exec("/system/bin/ping -c 1 8.8.8.8");
            int mExitValue = mIpAddrProcess.waitFor();
            System.out.println(" mExitValue "+mExitValue);
            if(mExitValue==0){
                return true;
            }else{
                return false;
            }
        }
        catch (InterruptedException ignore)
        {
            ignore.printStackTrace();
            System.out.println(" Exception:"+ignore);
        } 
        catch (IOException e) 
        {
            e.printStackTrace();
            System.out.println(" Exception:"+e);
        }
        return false;
    }