我正在尝试使用安卓设备上的smack API 4.1.2(无asmack)连接到ejabberd服务器。在运行smackClient程序时,我收到以下错误
java.net.SocketTimeOutException:Failed to connect to abc.example.com/182.*.*.* (on port 5222) after 30000ms,'abc.example.com:5222' failed because java.net.ConnectionException: Failed to connect to abc.example.com/182.*.*.* (on port 5222) after 30000ms
使用相同的Android设备连接到相同的ejabberd服务器使用像xabber这样的xmpp客户端正常工作。所以问题肯定与我写的客户端代码有关。以下是我的代码片段
XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword(userName, password)
.setServiceName("abc.example.com")
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
.setSendPresence(true)
.build();
connection = new XMPPTCPConnection(config);
connection.connect();
connection.login(userName, password);
我在我的客户端代码中遗漏了xabber所拥有的内容,因此xabber连接使用相同的凭据从同一设备工作。
请帮忙
答案 0 :(得分:0)
在您的示例中没有真正的IP和名称很难说清楚。但是,我最好的猜测是如何解析IP服务器的地址。
您的代码中的服务器(example.com)和服务名称(abc.example.com)似乎存在差异。
我猜你的客户端正在尝试连接到运行XMPP服务器的另一台机器。
因此,如果服务器没有回复问题,请检查以下内容:
答案 1 :(得分:0)
答案 2 :(得分:0)
我的经验:我使用了以下代码
DomainBareJid xmppServiceDomain = JidCreate.domainBareFrom("desktop-urvfr83");
//DomainBareJid xmppServiceDomain = JidCreate.domainBareFrom("192.168.1.3");
InetAddress addr = InetAddress.getByName("192.168.1.3");
XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword("alir", "111111")
.setHostAddress(addr)
.setResource("phonn")
.setXmppDomain(xmppServiceDomain)
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
.setPort(5222)
.build();
,但无法连接并产生超时连接异常。当我禁用Windows防火墙时,它可以正常工作并连接。