谁能告诉我为什么这在 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");
}
引发 UnknownHostException
谢谢