【问题标题】:Trying to connect XMPP server by Smack and getting error尝试通过 Smack 连接 XMPP 服务器并出现错误
【发布时间】:2025-12-30 21:35:16
【问题描述】:

我需要使用 Java API Smack 连接 XMPP 服务器并进一步发送消息/接收消息。

我尝试使用 Smack API (4.1.8),但出现错误(在下方查找错误)

注意:主机和端口都是打开的

Code:`public class Sender {
public static void main(String a[]) throws NoResponseException,XMPPException,
InterruptedException, SmackException, IOException
{
    // Create the configuration for this new connection
   XMPPTCPConnectionConfiguration.Builder configBuilder =  XMPPTCPConnectionConfiguration.builder();
    configBuilder.setUsernameAndPassword("user", "******");
    configBuilder.setResource("work");
    configBuilder.setServiceName("HOstname");
    configBuilder.setSocketFactory(SSLSocketFactory.getDefault());
    configBuilder.setSecurityMode(SecurityMode.required);

    configBuilder.setCompressionEnabled(true);
    configBuilder.setHost("thingsociety.im");
    configBuilder.setDebuggerEnabled(true);
    configBuilder.setPort(5222);
    System.out.println("Connected1..............");

    XMPPTCPConnection connection = new XMPPTCPConnection(configBuilder.build());
    // Connect to the server
    try {
        System.out.println("Connected2..............");
        connection.setPacketReplyTimeout(100000);
        connection.connect();
        System.out.println("Connected3..............");
        // Log into the server
        connection.isConnected();
        connection.login();
        System.out.println("Connected4..............");
    }

    catch (XMPPException | SmackException | IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
         System.out.println(e.getMessage());
         }
    }
}

错误:在回复超时内未收到回复。超时为 100000 毫秒(~100 秒)。使用的过滤器:未使用过滤器或过滤器为“空”。 org.jivesoftware.smack.SmackException$NoResponseException:在回复超时内没有收到回复。超时为 100000 毫秒(~100 秒)。使用的过滤器:未使用过滤器或过滤器为“空”

【问题讨论】:

    标签: xmpp smack


    【解决方案1】:

    所以基本上某些东西(本地防火墙或您的网关上)阻止了传出通信,或者 configBuilder.setServiceName("HOstname"); 服务名称(又名 XMPP 域)错误,可能拼写错误 - 特别是大写 O 对我来说似乎拼写错误。

    我刚刚探测了 thingsociety.im:5222,它是开放的,所以很可能是防火墙问题。

    另一个可能是服务器端未处理的低级错误。

    【讨论】:

      最近更新 更多