2012-06-04 47 views
1

我正在尝试为IM做一个无服务器应用程序。我使用apple bonjour协议来发现xmpp服务。但一旦我得到那些我无法连接到我的主机(Linux电脑使用pidgin + bonjour)。Xmpp连接在Android上使用asmack和bonjour

这里是我的代码(从here拍摄):

public class Xmpp extends AsyncTask<Void, Void, Void> 
{ 
    @Override 
    protected Void doInBackground(Void... arg0) 
    { 
     ConnectionConfiguration connConfig = 
       new ConnectionConfiguration("192.168.0.11", 5298, "bonjour"); 
     XMPPConnection connection = new XMPPConnection(connConfig); 
     try 
     { 
      // Connect to the server 
      connection.connect(); 
      // Most servers require you to login before performing other tasks. 
      connection.login("grea08", "mypass"); 
      // Start a new conversation with John Doe and send him a message. 
      Chat chat = connection.getChatManager().createChat("[email protected]", new MessageListener() { 


       public void processMessage(Chat chat, Message message) { 
        // Print out any messages we get back to standard out. 
        Log.v(getClass().getName(), "Received message: " + message); 
       } 
      }); 

      chat.sendMessage("Howdy!"); 
     } catch (XMPPException e) 
     { 
      // TODO Auto-generated catch block 
      Log.e(getClass().getName(), "Xmpp error !", e); 
     } 
     // Disconnect from the server 
     connection.disconnect(); 
     return null; 
    } 

} 

我有一个XmppException “服务器没有响应”。我认为主机不是XMPP服务器,我们必须使用协议this的方式。

+0

它确实是'192.189 ...'而不是'192.168 ...'?大多数内部IP地址是192.168.something。 – Jave

+0

啊是的一个简单的错误,谢谢,我正在努力 – grea09

+0

不是这不会导致“没有反应”错误。 – grea09

回答

1

啪和aSmack有XEP-0174(又名链路本地或无服务器通讯。)不支持。 Jonas patches从来没有进入树干。跟踪的相应问题是SMACK-262

+0

我怎样才能使用它呢? – grea09

+0

您可以尝试连接到SMACK-262的补丁。但它可能需要修改才能成功应用于Smack的当前主干。 – Flow

+0

我需要编译旧版本,还是可以修补更新的版本? 当我这样做时,我只需要使用“LL”类? XMPPLLConnection,LLPacketReader等? 有什么我需要知道的吗? – grea09

0

尝试创建XMPPConnection与配置:

ConnectionConfiguration config = new ConnectionConfiguration("192.189.0.11", port); 
//Set optional configurations on the config object. 
Connection connection = new XMPPConnection(config); 
+0

我刚刚尝试过,并且工作更进一步。现在我得到一个XMPP错误“服务器没有响应”。也许我做错了,因为主机不是xmpp服务器,而是另一个客户端。有没有办法发送消息,如本页所述http://xmpp.org/extensions/xep-0174.html? – grea09