安卓 HTTP 连接
2022-09-02 20:31:13
谁能告诉我为什么这在Android模拟器中不起作用?从我可以访问的浏览器,服务器是内部的。我能想到的是,我的应用程序缺少一些配置,因此它可以访问网络层。
try {
InetAddress server = Inet4Address.getByName("thehost");
//Doesn't work either
//or InetAddress server2 = Inet4Address.getByAddress(new String("192.168.1.30").getBytes());
if(server.isReachable(5000)){
Log.d(TAG, "Ping!");
}
Socket clientsocket = new Socket(server, 8080);
} catch (UnknownHostException e) {
Log.e(TAG, "Server Not Found");
} catch (IOException e) {
Log.e(TAG, "Couldn't open socket");
}
抛出未知主机异常
谢谢