2014-09-02 109 views
0

我使用的是erlang 17.0,ejabberd 14.07。我正在嘗試創建聊天應用程序,我已完成註冊部分。現在我想從註冊用戶登錄,但我無法登錄,所以如何在ejabberd上以用戶身份登錄。 基本上我的問題是,用戶如何成爲在ejabberd服務器上(在本地主機上)?以Ejabberd用戶身份登錄

我知道這是非常愚蠢的問題,但我無法找到任何方式引導我。

回答

0

使用函數yourconnection.login(username,password)。

0

首先確保您已成功通過命令

> sudo ejabberdctl registered_users localhost 

這將所有註冊用戶的localhost節點上列出的註冊用戶ejabberd。希望你會在那裏找到你的用戶。

現在您已成功設置您的ejabberd(XMPP服務器)。您需要XMPP客戶端才能讓用戶登錄。

所以,如果您使用的是java編程語言,那麼您應該使用SMACK XMPP庫連接到ejabberd服務器。使用此代碼與您的用戶名和密碼連接到ejabberd服務器。

// Create a connection to the igniterealtime.org XMPP server. 
XMPPTCPConnection con = new XMPPTCPConnection("igniterealtime.org"); 
// Connect to the server 
con.connect(); 
// Most servers require you to login before performing other tasks. 
con.login("jsmith", "mypass"); 
// Start a new conversation with John Doe and send him a message. 
Chat chat = ChatManager.getInstanceFor(con).createChat("[email protected]", new MessageListener() { 
    public void processMessage(Chat chat, Message message) { 
     // Print out any messages we get back to standard out. 
     System.out.println("Received message: " + message); 
    } 
}); 
chat.sendMessage("Howdy!"); 
// Disconnect from the server 
con.disconnect(); 

關於該代碼段的詳細信息,請訪問link

如果你想使用其他的客戶端比在Java中那麼這裏就是list of XMPP client libraries

連接到你需要ejabberd服務器後堅持這一方面發送和接收進一步的消息。

相關問題