java 为什么我无法连接到openfire服务器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6804236/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why can't I connect to the openfire server?
提问by Bar
I'm having a little bit of trouble trying to connect to Openfire (which I've installed on my computer) while using Smack.
在使用 Smack 时,我在尝试连接到 Openfire(我已安装在我的计算机上)时遇到了一些麻烦。
ConnectionConfiguration config = new ConnectionConfiguration("shin-pc" ,5222);
config.setCompressionEnabled(true);
config.setSASLAuthenticationEnabled(true);
XMPPConnection connection = new XMPPConnection(config);
connection.connect();
connection.login("test", "test");
When I try debugging or running, there's an error of some sort in the connect()
line.
当我尝试调试或运行时,行中出现某种错误connect()
。
XMPPError connecting to localhost:5222.: remote-server-error(502) XMPPError connecting to localhost:5222. -- caused by: java.net.SocketException: Permission denied.
XMPPError 连接到 localhost:5222.: remote-server-error(502) XMPPError 连接到 localhost:5222。-- 引起:java.net.SocketException:权限被拒绝。
I've tried switching the host name to "localhost", and it didn't work either.
我试过将主机名切换为“localhost”,但也没有用。
I have no experience in this XMPP business so I guess it's a common newbie problem or something of the sort...
我在这个 XMPP 业务方面没有经验,所以我猜这是一个常见的新手问题或类似的问题......
What might be the problem? How can I fix this so the connection will be successful?
可能是什么问题?如何解决此问题以便连接成功?
回答by Jave
I just created a new project in which I need XMPP, and ran into the same problem. However, I realized that it was simply because I had forgotten to add the internet permission in my manifest:
我刚刚创建了一个需要 XMPP 的新项目,但遇到了同样的问题。但是,我意识到这仅仅是因为我忘记在清单中添加互联网权限:
<uses-permission android:name="android.permission.INTERNET"/>
Make sure that you haven't done the same mistake.
确保你没有犯过同样的错误。
回答by Ajay
I have Same problem .... but i resolved this issue at my end using following steps :::
我有同样的问题......但我最终使用以下步骤解决了这个问题:::
1) Firstly checked Internet permission
1)首先检查互联网权限
<uses-permission android:name="android.permission.INTERNET"/>
2) Then open the openfire.xml file from C:\Openfire\conf (Installation directory) and edit the file
2)然后从C:\Openfire\conf(安装目录)打开openfire.xml文件,编辑文件
<network>
<interface>Your IP Address(192.168.0.1)</interface>
</network>
and save the file and start the openfire server. I think it will be helpful for you....
并保存文件并启动 openfire 服务器。我想它会对你有帮助......
回答by sofiane
i had the same problem, i followed these steps to solve it:
我遇到了同样的问题,我按照以下步骤来解决它:
disable your firewall first
use your the IP address of your server openfire
首先禁用防火墙
使用您的服务器 openfire 的 IP 地址
回答by Rahul Arora
Use host as localhost if you are using a device. If you are using an emulator, use ip address (192.168.1.2 or whatever) in the configuration step (line 1 of the given code)
如果您使用的是设备,请使用主机作为 localhost。如果您使用的是模拟器,请在配置步骤(给定代码的第 1 行)中使用 ip 地址(192.168.1.2 或其他)