Android客户端与jboss服务器通信
我的 Android 客户端与部署在 jboss 上的 servlet 建立 URL 连接。但是当我在模拟器中运行客户端时,似乎没有建立连接。我的客户端代码:
URL url = new URL("http://192.168.56.1:8080/hello");
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
ObjectOutputStream out=new ObjectOutputStream(connection.getOutputStream());
String s=new String("success");
out.writeObject(s);
out.flush();
out.close();
jboss没有响应。 192.168.56.1是我机器的IP地址。由于“localhost”将引用模拟器本身,因此我使用了 192.168.56.1。(ipcofig) 问题是什么。
这是在我做出建议的更改之后(即在 android manifest.xml 中授予互联网权限并将 url 更改为“http://10.0.2.2:8080/hello”以引用我的机器)。 但当我运行我的应用程序(客户端)时,我仍然遇到此异常:
ActivityManager: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.Client/.ClientActivity } from null (pid=-1, uid=-1) requires android.permission.INTERNET
现在它正在工作。我将互联网权限添加到清单标签中。早些时候我已将其添加到应用程序标签内。 参考我原来的问题,即使在进行了所有建议的更改后,jboss 服务器仍然没有响应。模拟器和 jboss 服务器之间似乎没有建立连接。
My android client makes a URLconnection to a servlet deployed on jboss. But when i run the client in emulator there seems to be no connection being established. My client code:
URL url = new URL("http://192.168.56.1:8080/hello");
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
ObjectOutputStream out=new ObjectOutputStream(connection.getOutputStream());
String s=new String("success");
out.writeObject(s);
out.flush();
out.close();
There is no response in jboss. 192.168.56.1 is the ip address of my machine. Since 'localhost' will refer to the emulator itself, I have used 192.168.56.1.(ipcofig)
What is the problem.
This is after I made the suggested changes(i.e gave the internet permission in android manifest.xml and changed the url to 'http://10.0.2.2:8080/hello' to refer to my machine).
But i still get this exception when I run my application(Client):
ActivityManager: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.Client/.ClientActivity } from null (pid=-1, uid=-1) requires android.permission.INTERNET
Now it is working. I added the in internet permission to the manifest tag. Earlier I had added it inside the application tag.
With reference to my original question, still there is no response from the jboss server evene after making all the suggested changes. There seems to be no connection being made between the emulator and the jboss server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,假设您的 JBoss 服务器与模拟器在同一台 PC 上运行,此处
您可以检查以下几项内容:
首先,请确保您的计算机中设置了
Internet
权限AndroidManifest.xml
为Thinksteep
指出:
其次,尝试更改 IP 地址:
至:
详细信息 此处。从本质上讲,这样做是假设您的 JBoss 在开发计算机上由
localhost
提供服务(即由127.0.0.1
提供服务),您的模拟器应该能够通过这个特殊的IP地址。So assuming your JBoss server is running on the same PC as your emulator, here
are a few things you can check:
First off, make sure you have the
Internet
permission set in yourAndroidManifest.xml
asThinksteep
pointed out:
Secondly, try changing the IP address in:
To:
Details here. Essentially what this is doing is that assuming you have your JBoss serving off
localhost
on your development machine (i.e. serving off127.0.0.1
), your emulator should be able to connect via this special IP address.