【发布时间】:2010-10-01 08:18:57
【问题描述】:
谁能告诉我为什么这在 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
谢谢
【问题讨论】:
标签: java android sockets network-programming