2012-09-12 69 views
1

我正在使用libjingle編寫一些代碼,並在第一步遇到問題:登錄到XMPP服務器。我的代碼基於sample code from goog和pcp示例代碼。該代碼讓我感到困惑,因爲它似乎只運行一個線程,所以我意識到這是一個非常基本的問題。使用libjingle登錄到XMPP

總之,這裏的肉和我的代碼土豆:

talk_base::PhysicalSocketServer ss; 
    talk_base::AutoThread main_thread(&ss); 
    buzz::Jid jid(xmppUsername + "@" + xmppHost); 
    if (!jid.IsValid() || jid.node() == "") 
     throw "Invalid JID. JIDs should be in the form [email protected]" ; 

    buzz::TlsOptions tls = buzz::TLS_ENABLED; 

    buzz::XmppClientSettings xcs; 
    xcs.set_user(jid.node()); 
    xcs.set_host(jid.domain()); 
    xcs.set_resource("pcp"); 
    xcs.set_pass(talk_base::CryptString(pass)); 
    xcs.set_allow_plain(true); 
    xcs.set_server(talk_base::SocketAddress(xmppHost.c_str(), 5222)); 
    xcs.set_use_tls(tls); 

    // Log in. 
    CustomXmppPump pump; 
    pump.client()->SignalLogInput.connect(&debug_log_, &DebugLog::Input); 
    pump.client()->SignalLogOutput.connect(&debug_log_, &DebugLog::Output); 
    pump.DoLogin(xcs, new XmppSocket(tls), 0); 

    // Wait until login succeeds. 
    std::vector<uint32> ids; 
    ids.push_back(MSG_LOGIN_COMPLETE); 
    ids.push_back(MSG_LOGIN_FAILED); 
    if (MSG_LOGIN_FAILED == Loop(ids)) 
     throw "Failed to connect"; 

    ... 

    // Runs the current thread until a message with the given ID is seen. 
    uint32 Loop(const std::vector<uint32>& ids) { 
     talk_base::Message msg; 
     while (talk_base::Thread::Current()->Get(&msg)) { 
     cout << "received message: " << msg.message_id << endl; 
     if (msg.phandler == NULL) { 
      if (std::find(ids.begin(), ids.end(), msg.message_id) != ids.end()) 
      return msg.message_id; 
      std::cout << "orphaned message: " << msg.message_id << endl; 
      continue; 
     } 
     cout << "1: " << msg.message_id << " : " << msg.ts_sensitive << endl; 
     talk_base::Thread::Current()->Dispatch(&msg); 
     cout << "2: " << msg.message_id << endl; 
     } 
     return 0; 
    } 

運行時,它輸出:

 
connecting... 
received message: 0 
1: 0 : 0 
[004:722] Resolving addr in PhysicalSocket::Connect 
2: 0 
received message: 0 
1: 0 : 0 
2: 0 

而只是掛起,那麼顯然它被陷在獲取(&味精)電話。

我應該注意到,我的服務器使用DNS SRV記錄,並可以很好地與其他客戶端 - 可能我只需要自己解決SRV?

感謝您的幫助!

回答

1

牛逼回答我的問題:

根據this bug,和我自己的測試,DNS SRV不支持。

此外,根據this bug,文檔已過時,我使用的示例代碼不是推薦的示例代碼。

不過,我能夠取得一些進展,在呼叫設定域登錄:

xcs.set_server(talk_base::SocketAddress(xmppHost.c_str(), 5222)); 

託管服務的實際服務器的值。我想我已經嘗試過這一點,但它並沒有工作,因爲我實際上已經改變了這一點:

xcs.set_host(jid.domain()); 

哎呀。

+0

對於其他人走這條道路,我會建議看看最新的方式通過XMPP與libjingle登錄調用示例。 – Zack