[英]Smack Android client fails to connect to ejabberd server
我已经在这个问题上停留了6个多小时,我已经通过互联网检查了数百种解决方案,但对我来说却无济于事。
我正在通过Smack 4.2实现XMPP Android客户端,以下是我的gradle依赖项:
compile "org.igniterealtime.smack:smack-android-extensions:4.2.0"
compile "org.igniterealtime.smack:smack-tcp:4.2.0"
我已在清单中声明允许:
<uses-permission android:name="android.permission.INTERNET" />
这是我连接到服务器的代码
private class LoginTask extends AsyncTask<UserProps, String, String> {
@Override
protected String doInBackground(UserProps... props){
try {
InetAddress addr = InetAddress.getByName("192.168.100.5");
HostnameVerifier verifier = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return false;
}
};
DomainBareJid serviceName = JidCreate.domainBareFrom("rabta");
XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword(props[0].getUser(), props[0].getPass())
.setHostAddress(addr)
.setXmppDomain(serviceName)
.setHostnameVerifier(verifier)
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
.setPort(5222)
.setDebuggerEnabled(true)
.build();
AbstractXMPPConnection conn = new XMPPTCPConnection(config);
conn.connect();
if(conn.isConnected()) {
Log.w("app", "connected--------------------------");
}
conn.login();
if(conn.isAuthenticated()) {
Log.w("app", "authenticated----------------------");
}
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (SmackException e) {
e.printStackTrace();
} catch (XMPPException e) {
e.printStackTrace();
}
return "";
}
@Override
protected void onPostExecute(String result) {
}
}
其中192.168.100.5
是安装了ejabberd的Windows 10计算机的ipv4地址。 rabta
是我在安装时指定的服务器名称,而不是localhost
。 我的服务器不在实时IP上。 我的客户端和服务器都在同一WiFi网络上。
org.jivesoftware.smack.SmackException$ConnectionException: The following addresses failed: 'null:5222' failed because: /192.168.100.5
exception: java.net.ConnectException: failed to connect to /192.168.100.5 (port 5222) after 30000ms: isConnected failed: ECONNREFUSED (Connection refused)
01-05 05:16:19.757 18413-18591/com.rabta.rabta W/System.err: at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectUsingConfiguration(XMPPTCPConnection.java:617)
我在启动ejabberd时收到的消息
By default, the ejabberd Web Admin interface is enabled. You should be able to connect to the admin interface and log in with the user admin@rabta and the password you defined during the installation.
Users can connect to your server 'rabta' with any Jabber/XMPP
The name of the current ejabberd node is ejabberd@localhost.
要登录的用户凭据:用户名user1@rabta
密码pass
,最后是ejabberd.yml
hosts:
- "rabta"
listen:
-
port: 5222
ip: "::"
module: ejabberd_c2s
starttls: true
在服务器计算机上,我具有管理员权限,并且所有防火墙都已关闭。 如果有人可以帮助我,我将非常高兴。 提前致谢
简短答案:使用Linux
而不是Windows
经过大量尝试,我发现我的客户端或服务器没有问题。 问题出在Windows。
当我从Windows
内部检查端口及其监听过程时,我可以看到Erlang
正在监听port:5222
,但是当我从外部扫描端口时,我意识到该端口已关闭。 尝试了防火墙和网络的所有技巧,但没有成功。
从Windows
切换到Linux
,一切都变得像个魅力!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.