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?
感謝您的幫助!
對於其他人走這條道路,我會建議看看最新的方式通過XMPP與libjingle登錄調用示例。 – Zack