簡體   English   中英

使用java連接到xmpp(openfire)服務器時出錯

[英]error in connect to xmpp(openfire) server using java

我是XMPP的新手。 一整天我都無法從Java連接到我的XMPP服務器(Openfire版本3.9.3)。 我正在使用Smack(版本4.0.7)庫。 這是簡單的代碼......

ConnectionConfiguration config =new ConnectionConfiguration("servername",5223);
XMPPTCPConnection connection = new XMPPTCPConnection(config);
    // Connect to the server
    try {
            connection.connect();
        connection.login("username", "password");

        }  catch (IOException e) {
            e.printStackTrace();
        } catch (XMPPException e) {
            e.printStackTrace();
        } catch (SmackException e) {
            e.printStackTrace();
        } 

但是,當我運行此代碼時,此錯誤顯示...

org.jivesoftware.smack.SmackException$NoResponseException
at org.jivesoftware.smack.XMPPConnection.throwConnectionExceptionOrNoResponse(XMPPConnection.java:548)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.throwConnectionExceptionOrNoResponse(XMPPTCPConnection.java:867)
at org.jivesoftware.smack.tcp.PacketReader.startup(PacketReader.java:113)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.initConnection(XMPPTCPConnection.java:482)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectUsingConfiguration(XMPPTCPConnection.java:440)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection.java:811)
at org.jivesoftware.smack.XMPPConnection.connect(XMPPConnection.java:396)
at test.third.<init>(third.java:19)
at test.third.main(third.java:34)

可能存在一個愚蠢的錯誤和簡單的解決方案。 我用谷歌搜索,但不知何故,我沒有得到正確的解決方案。

public  void connectAndLogin( {

    connect();
    login();

}

private void connect() {
    /**
     * Set server configuration
     * 
     * connect to server    
     */
    setConfiguration();
    try {
        getConnection().connect();
    } catch (XMPPException e) {
        e.printStackTrace();
        setConnection(null);
    }
    }

    private void setConfiguration() {
        ConnectionConfiguration config = new ConnectionConfiguration(Constants.IP);
        SmackConfiguration.setPacketReplyTimeout(Constants.PACKET_TIME_OUT);
        System.out.println(SmackConfiguration.getVersion());
        config.setRosterLoadedAtLogin(false);
        // config.setCompressionEnabled(true);
        config.setVerifyChainEnabled(false);
        config.setReconnectionAllowed(true);
        config.setSASLAuthenticationEnabled(false);
        config.setSecurityMode(SecurityMode.disabled);
        config.setDebuggerEnabled(false);
        connection = new XMPPConnection(config);
}

private void login() {
    if(getConnection()!=null){


    String USER_NAME="";

    String PASSWORD="";

    try {
        getConnection().login(USER_NAME,PASSWORD, Constants.RESOURCE);
    } catch (Exception e) {
        e.printStackTrace();
    }



    }
}

嘗試使用端口5222而不是5223.這是舊的SSL方式,通常不再使用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM