谁能告诉我为什么不能在Android模拟器的工作?从浏览器我有机会和服务器内部。所有我能想到的是,我很想念我的应用程序的一些配置,以便它可以访问网络层。
Can anybody tell my why this doesn't work in the Android emulator? From the browser I have access and the server is internal. All I can think of is that I'm missing some configuration on my app so it can access the network layer.
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
感谢
至于配置的推移,唯一的设定,你应该需要从应用程序访问互联网是互联网的权限,通过添加以下行启用的外的应用程序中的应用程序标签清单。
As far as configuration goes, the only setting you should need to access the Internet from your application is the INTERNET permission, enabled by adding the following line outside the Application tags within your application Manifest.
<uses-permission android:name="android.permission.INTERNET" />
因此,清单将遵循这一总建筑
So the manifest would follow this general construction
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.apis">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="MyApplication"
android:label="@string/application_title"
android:icon="@drawable/my_icon">
[ .. Your Activities go here ]
</application>
</manifest>
上一篇:测量 Linux 多线程应用程序的堆栈使用情况堆栈、多线程、应用程序、测量
下一篇:使用 std::stack 而不是 deque、vector 或 list 有什么优点和缺点有什么、而不是、缺点、优点