Ejemplo n.º 1
0
        private string BuildPostData()
        {
            CurrentKeyIdx--;
            rid++;

            StringBuilder sb = new StringBuilder();

            Body body = new Body();

            body.Rid        = rid;
            body.Key        = Keys[CurrentKeyIdx];

            if (CurrentKeyIdx == 0)
            {
                // this is our last key
                // Generate a new key sequence
                GenerateKeys();
                body.NewKey = Keys[CurrentKeyIdx];
            }

            body.Sid        = sid;
            //body.Polling    = 0;
            body.To = new Jid(m_XmppCon.Server);

            if (restart)
            {
                body.XmppRestart = true;
                restart = false;
            }

            lock (m_SendQueue)
            {
                if (terminate && m_SendQueue.Count == 1)
                    body.Type = BoshType.terminate;

                if (m_SendQueue.Count > 0)
                {
                    sb.Append(body.StartTag());

                    while (m_SendQueue.Count > 0)
                    {
                        string data = m_SendQueue.Dequeue() as string;
                        sb.Append(data);
                    }

                    sb.Append(body.EndTag());

                    return sb.ToString();
                }
                else
                    return body.ToString();
            }
        }
Ejemplo n.º 2
0
        public void RequestBoshSession()
        {
            /*
            Example 1. Requesting a BOSH session

            POST /webclient HTTP/1.1
            Host: httpcm.jabber.org
            Accept-Encoding: gzip, deflate
            Content-Type: text/xml; charset=utf-8
            Content-Length: 104

            <body content='text/xml; charset=utf-8'
                  hold='1'
                  rid='1573741820'
                  to='jabber.org'
                  route='xmpp:jabber.org:9999'
                  secure='true'
                  ver='1.6'
                  wait='60'
                  ack='1'
                  xml:lang='en'
                  xmlns='http://jabber.org/protocol/httpbind'/>
             */

            lastSend = DateTime.Now;

            // Generate the keys
            GenerateKeys();
            rid = GenerateRid();
            Body body = new Body();
            /*
             * <body hold='1' xmlns='http://jabber.org/protocol/httpbind'
             *  to='vm-2k'
             *  wait='300'
             *  rid='782052'
             *  newkey='8e7d6cec12004e2bfcf7fc000310fda87bc8337c'
             *  ver='1.6'
             *  xmpp:xmlns='urn:xmpp:xbosh'
             *  xmpp:version='1.0'/>
             */

            body.Version        = BOSH_VERSION;
            body.XmppVersion    = "1.0";
            body.Hold           = m_Hold;
            body.Wait           = m_Wait;
            body.Rid            = rid;
            body.Polling        = 0;
            body.Requests       = m_Requests;
            body.To             = new Jid(m_XmppCon.Server);

            body.NewKey         = Keys[CurrentKeyIdx];

            body.SetAttribute("xmpp:xmlns", "urn:xmpp:xbosh");

            waitingRequests++;

            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(Address);

            WebRequestState state = new WebRequestState(req);
            state.Started           = DateTime.Now;
            state.Output            = body.ToString();
            state.IsSessionRequest  = true;

            req.Method          = METHOD;
            req.ContentType     = CONTENT_TYPE;
            req.Timeout         = m_Wait * 1000;
            req.KeepAlive       = m_KeepAlive;
            req.ContentLength   = state.Output.Length;

            try
            {
                IAsyncResult result = req.BeginGetRequestStream(new AsyncCallback(this.OnGetSessionRequestStream), state);
            }
            catch (Exception)
            {
            }
        }