1

如何知道服务器/IP 地址在 android 中可用/已连接。我试试这段代码

final EditText ed_ip = (EditText)findViewById(R.id.ed_server);
Button btn_ip_save = (Button)findViewById(R.id.btn_save_ip);

btn_ip_save.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

String str_serverip = ed_ip.getText().toString();
int timeout = 2000;

byte [] b = str_serverip.getBytes();

boolean addr = InetAddress.getByAddress(b).isReachable(timeout);

if(addr == true)
{
       txt.setText("Response");
      Toast.makeText(IpConfig.this, "Reachable", Toast.LENGTH_LONG).show();

}else {

    txt.setText("Not Response");
    Toast.makeText(IpConfig.this, "Not", Toast.LENGTH_LONG).show();
    }


}       

它总是拒绝连接,除了 127.0.0.1

如何检查请指导我..

4

0 回答 0