Search code examples
xmppgoogle-talk

gtalk(XMPP) initial response not always contain a <stream:features>


i send to talk.google.com with a initial stanza like:

<?xml version='1.0'?>
<stream:stream
from='[email protected]'
to='gmail.com'
version='1.0'
xml:lang='en'
xmlns='jabber:client'
xmlns:stream='http://etherx.jabber.org/streams'>

and as the rfc6120 said, server should response with a stanza that has tag named "stream:features"

but I've tried a lot of time but the response rarely contained the "stream:features" so I have to make a circulation waiting for a response which contains a "stream:features".


Solution

  • You should get a stream:stream open tag before the stream:features:

    <stream:stream xmlns:stream="http://etherx.jabber.org/streams" 
                   xmlns="jabber:client" 
                   from="gmail.com" 
                   id="407014FD9646082B" 
                   version="1.0">
      <stream:features>
        <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls">
          <required/>
        </starttls>
        <mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
          <mechanism>X-GOOGLE-TOKEN</mechanism>
          <mechanism>X-OAUTH2</mechanism>
        </mechanisms>
      </stream:features>
    

    I'd urge you to use one of the existing client libraries linked to at xmpp.org. You're likely to have a bunch of other problems before you've got something running well if you're doing synchronous reads.