任何人都可以告诉我为什么这在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
谢谢
就配置而言,从应用程序访问Internet所需的唯一设置是INTERNET权限,通过在应用程序清单中的Application标记之外添加以下行来启用.
因此清单将遵循这种一般结构
[ .. Your Activities go here ]