2010-06-04 37 views
1

我目前正在开发android XMPP客户端以与Tigase服务器设置进行本地通信。在Android上开始开发之前,我正在编写一个简单的Java代码以测试与XMPP服务器的连接。我的XMPP域名是我的电脑名称“mwbn43-1”,管理员用户名和密码分别是admin和tigase。Smack API在本地登录到Tigase Server设置时出错

以下是代码我使用

class Test { 

public static void main(String args[])throws Exception 
{ 

System.setProperty("smack.debugEnabled", "true"); 
XMPPConnection.DEBUG_ENABLED = true; 

ConnectionConfiguration config = new ConnectionConfiguration("mwbn43-1", 5222); 
config.setCompressionEnabled(true); 
config.setSASLAuthenticationEnabled(true); 

XMPPConnection con = new XMPPConnection(config); 

// Connect to the server 
con.connect(); 
con.login("admin", "tigase"); 

Chat chat = con.getChatManager().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); 
     } 
    }); 
     try { 
     chat.sendMessage("Hi!"); 
    } 
    catch (XMPPException e) { 
     System.out.println("Error Delivering block"); 
    } 


String host = con.getHost(); 
String user = con.getUser(); 
String id = con.getConnectionID(); 
int port = con.getPort(); 
boolean i = false; 
i = con.isConnected(); 
if (i) 
System.out.println("Connected to host " + host + " via port " + port + " connection id is " + id); 

System.out.println("User is " + user); 
con.disconnect(); 
} 
} 

当我运行这段代码我获得以下错误

Exception in thread "main" Resource binding not offered by server: 
at org.jivesoftware.smack.SASLAuthentication.bindResourceAndEstablishSession(SASLAuthenticatio  n.java:416) at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:331) 
at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:395) 
at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:349) 
at Test.main(Test.java:26) 

我发现了同样的问题,这个文章,但没有具体的解决方案 片断here 任何人都可以告诉我这个问题的解决方案。我检查了Smack API中的XMPPConnection.java文件,它看起来与链接解决方案中给出的相同。

感谢, Ameya

回答

3

我找到了解决问题的方法,如here

给这些之前,我连接到服务器

ConnectionConfiguration config = new ConnectionConfiguration("mwbn43-1", 5222); 
config.setSASLAuthenticationEnabled(false); 
XMPPConnection xmpp = new XMPPConnection(config); 

感谢您的帮助,我要补充的线

-1

我觉得这是图书馆,一个错误的问题。它不能正确处理协议。在用户通过身份验证之前,没有发送资源绑定的要点,因此它不会被服务器通告。客户不应该抱怨。

+0

我应该怎么为了使它正常工作。我尝试了与Gtalk服务器相同的代码,并且它的工作正常。所以我想问题是服务器的设置问题(某些资源问题)。我应该在服务器端做什么? – 2010-06-06 07:28:18