title: Logging on to XMPP using libjingle
body: <p>I am writing some code using libjingle and having trouble with the first step: logging on to the XMPP server. My code is based on the <a href="https://developers.google.com/talk/libjingle/login" rel="nofollow">sample code from goog</a> and the pcp sample code. That code confuses me a bit because it appears to only run one thread, so I realize this is an extremely basic question.</p>
  
  <p>Anyway, here's the meat and potatoes of my code:</p>
  
  <pre><code>    talk_base::PhysicalSocketServer ss;
      talk_base::AutoThread main_thread(&amp;ss);
      buzz::Jid jid( xmppUsername + "@" + xmppHost );
      if (!jid.IsValid() || jid.node() == "")
          throw "Invalid JID. JIDs should be in the form user@domain" ;
  
      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()-&gt;SignalLogInput.connect(&amp;debug_log_, &amp;DebugLog::Input);
      pump.client()-&gt;SignalLogOutput.connect(&amp;debug_log_, &amp;DebugLog::Output);
      pump.DoLogin(xcs, new XmppSocket(tls), 0);
  
      // Wait until login succeeds.
      std::vector&lt;uint32&gt; 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&lt;uint32&gt;&amp; ids) {
        talk_base::Message msg;
        while (talk_base::Thread::Current()-&gt;Get(&amp;msg)) {
          cout &lt;&lt; "received message: " &lt;&lt; msg.message_id &lt;&lt; endl;
          if (msg.phandler == NULL) {
            if (std::find(ids.begin(), ids.end(), msg.message_id) != ids.end())
              return msg.message_id;
            std::cout &lt;&lt; "orphaned message: " &lt;&lt; msg.message_id &lt;&lt; endl;
            continue;
          }
          cout &lt;&lt; "1: " &lt;&lt; msg.message_id &lt;&lt;  " : " &lt;&lt; msg.ts_sensitive &lt;&lt; endl;
          talk_base::Thread::Current()-&gt;Dispatch(&amp;msg);
          cout &lt;&lt; "2: " &lt;&lt; msg.message_id &lt;&lt; endl;
        }
        return 0;
      }
  </code></pre>
  
  <p>When run, it outputs:</p>
  
  <pre>
  connecting...
  received message: 0
  1: 0 : 0
  [004:722] Resolving addr in PhysicalSocket::Connect
  2: 0
  received message: 0
  1: 0 : 0
  2: 0
  </pre>
  
  <p>And just hangs, so clearly it's getting stuck on the Get(&amp;msg) call.</p>
  
  <p>I should note that my server uses the DNS SRV record and works fine with other clients -- maybe I just need to resolve the SRV myself?</p>
  
  <p>Thanks for any help!</p>