从主机名解析通过wifi网络android以编程方式连接的其他设备的IP地址

时间:2015-12-19 12:27:12

标签: android web-services wifi hostname inetaddress

从我的测试android设备我希望通过妻子网络连接的特定设备的主机名获取IP地址下面的代码在一些测试Android设备运行正常但在其他设备中它给我UnknownHostException,为什么它不解析IP地址在某些设备?

    <?php
    $data = json_decode(file_get_contents("php://input"));

    $email = $data->email;
    $mobile = $data->mobile;
    $text = $data->text;

    require_once("connection.php");

    $connection = connectToMySQL();
    $query = "INSERT INTO tbl_contactus (email, mobile, text) VALUES ('$email', '$mobile', '$text')";
    $result = mysqli_query($connection, $query)
         or die("Error in query: ". mysqli_error($connection));

    if(mysqli_affected_rows($connection) > 0){
            $success = true;
    }else{
            $success = false;
    }

    echo json_encode($success);
?>

从DNS服务器搜索IP地址的代码 -

InetAddress inetaddress=InetAddress.getByName("HostName");
System.out.println("address="+inetaddress.getHostAddress());

任何人都可以优化此代码吗?

0 个答案:

没有答案