Example #1
0
        public void FindDeviceAsync(string SearchTarget)
        {
            HTTPMessage packet = new HTTPMessage();

            packet.Directive    = "M-SEARCH";
            packet.DirectiveObj = "*";
            packet.AddTag("ST", SearchTarget);
            packet.AddTag("MX", MX.ToString());
            packet.AddTag("MAN", "\"ssdp:discover\"");
            packet.AddTag("HOST", "239.255.255.250:1900");
            IPAddress[] localAddresses = this.NetInfo.GetLocalAddresses();
            IPEndPoint  dest           = new IPEndPoint(IPAddress.Parse("239.255.255.250"), 0x76c);

            for (int i = 0; i < localAddresses.Length; i++)
            {
                try
                {
                    Socket theSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                    theSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
                    theSocket.Bind(new IPEndPoint(localAddresses[i], 0));
                    SSDPSession session = new SSDPSession(theSocket, new SSDPSession.ReceiveHandler(this.HandleAsyncSearch));
                    this.SSDPSessions[session] = session;
                    session.SendTo(packet, dest);
                    session.SendTo(packet, dest);
                    this.Lifetime.Add(session, 7);
                }
                catch (Exception exception)
                {
                    EventLogger.Log(this, EventLogEntryType.Error, "CP Failure: " + localAddresses[i].ToString());
                    EventLogger.Log(exception);
                }
            }
        }
Example #2
0
 private void FetchServiceDocuments(UPnPDevice device)
 {
     for (int i = 0; i < device.Services.Length; i++)
     {
         HTTPMessage message  = new HTTPMessage();
         Uri         resource = new Uri(device.Services[i].SCPDURL);
         message.Directive    = "GET";
         message.DirectiveObj = HTTPMessage.UnEscapeString(resource.PathAndQuery);
         message.AddTag("Host", resource.Host + ":" + resource.Port.ToString());
         this.r.PipelineRequest(resource, device.Services[i]);
     }
     if (device.EmbeddedDevices.Length > 0)
     {
         for (int j = 0; j < device.EmbeddedDevices.Length; j++)
         {
             this.FetchServiceDocuments(device.EmbeddedDevices[j]);
         }
     }
 }
Example #3
0
        private void ContinueRequest(IPEndPoint dest, string PQ, object Tag, HTTPMessage MSG)
        {
            HTTPMessage mSG = null;

            if (MSG == null)
            {
                mSG              = new HTTPMessage();
                mSG.Directive    = "GET";
                mSG.DirectiveObj = PQ;
                mSG.AddTag("Host", dest.ToString());
            }
            else
            {
                mSG = MSG;
            }
            lock (this.TagQueue)
            {
                this.IdleTimeout = false;
                KeepAliveTimer.Remove(this.GetHashCode());
                this.LastMessage = mSG;
                if ((!PIPELINE && !this._PIPELINE) || !this._PIPELINE)
                {
                    HTTPRequest request = new HTTPRequest();
                    request.ProxySetting = this.ProxySetting;
                    request._PIPELINE    = true;
                    if (this.OnSniff != null)
                    {
                        request.OnSniff = (SniffHandler)Delegate.Combine(request.OnSniff, new SniffHandler(this.NonPipelinedSniffSink));
                    }
                    if (this.OnSniffPacket != null)
                    {
                        request.OnSniffPacket = (RequestHandler)Delegate.Combine(request.OnSniffPacket, new RequestHandler(this.NonPipelinedSniffPacketSink));
                    }
                    request.OnResponse = (RequestHandler)Delegate.Combine(request.OnResponse, new RequestHandler(this.NonPipelinedResponseSink));
                    this.NotPipelinedTable[request] = request;
                    request.PipelineRequest(dest, mSG, Tag);
                }
                else
                {
                    bool flag = this.TagQueue.Count == 0;
                    this.TagQueue.Enqueue(new StateData(mSG, dest, Tag, null));
                    if (this.s == null)
                    {
                        this.ReceivedFirstResponse = false;
                        if (this.ProxySetting != null)
                        {
                            this.s = new HTTPSession(new IPEndPoint(IPAddress.Any, 0), this.ProxySetting, new HTTPSession.SessionHandler(this.CreateSink), new HTTPSession.SessionHandler(this.CreateFailedSink), null);
                        }
                        else
                        {
                            this.s = new HTTPSession(new IPEndPoint(IPAddress.Any, 0), dest, new HTTPSession.SessionHandler(this.CreateSink), new HTTPSession.SessionHandler(this.CreateFailedSink), null);
                        }
                    }
                    else if (this.s.IsConnected && this.ReceivedFirstResponse)
                    {
                        try
                        {
                            if (this.ProxySetting == null)
                            {
                                this.s.Send(mSG);
                            }
                            else
                            {
                                HTTPMessage packet = (HTTPMessage)mSG.Clone();
                                packet.DirectiveObj = "http://" + dest.ToString() + packet.DirectiveObj;
                                packet.Version      = "1.0";
                                this.s.Send(packet);
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }
        }