Android客户端与jboss服务器通信

发布于 2025-01-02 22:02:24 字数 1145 浏览 4 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暖心男生 2025-01-09 22:02:24

因此,假设您的 JBoss 服务器与模拟器在同一台 PC 上运行,此处
您可以检查以下几项内容:

首先,请确保您的计算机中设置了 Internet 权限
AndroidManifest.xml
Thinksteep
指出:

<uses-permission android:name="android.permission.INTERNET" />

其次,尝试更改 IP 地址:

URL url = new URL("http://192.168.56.1:8080/hello");

至:

URL url = new URL("http://10.0.2.2:8080/hello");

详细信息 此处。从本质上讲,这样做是假设您的 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 your
AndroidManifest.xml as
Thinksteep
pointed out:

<uses-permission android:name="android.permission.INTERNET" />

Secondly, try changing the IP address in:

URL url = new URL("http://192.168.56.1:8080/hello");

To:

URL url = new URL("http://10.0.2.2:8080/hello");

Details here. Essentially what this is doing is that assuming you have your JBoss serving off localhost on your development machine (i.e. serving off 127.0.0.1), your emulator should be able to connect via this special IP address.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文