Beispiel #1
0
 public bool IsConnected()
 {//Will send a request to the DLNA server and then see if we get a valid reply
     Connected = false;
     try
     {
         Socket SocWeb = HelperDLNA.MakeSocket(this.IP, this.Port);
         SocWeb.Send(Encoding.UTF8.GetBytes(HelperDLNA.MakeRequest("GET", this.SMP, 0, "", this.IP, this.Port)), SocketFlags.None);
         this.HTML = HelperDLNA.ReadSocket(SocWeb, true, ref this.ReturnCode);
         if (this.ReturnCode != 200)
         {
             return(false);
         }
         this.Services = DLNAService.ReadServices(HTML);
         if (this.HTML.ToLower().IndexOf("<friendlyname>") > -1)
         {
             this.FriendlyName = this.HTML.ChopOffBefore("<friendlyName>").ChopOffAfter("</friendlyName>").Trim();
         }
         foreach (DLNAService S in this.Services.Values)
         {
             if (S.ServiceType.ToLower().IndexOf("avtransport:1") > -1)//avtransport is the one we will be using to control the device
             {
                 this.ControlURL = S.controlURL;
                 this.Connected  = true;
                 return(true);
             }
         }
     }
     catch {; }
     return(false);
 }
Beispiel #2
0
        public static Dictionary <string, DLNAService> ReadServices(string HTML)
        {
            Dictionary <string, DLNAService> Dic = new Dictionary <string, DLNAService>();

            HTML = HTML.ChopOffBefore("<serviceList>").ChopOffAfter("</serviceList>").Replace("</service>", "¬");
            foreach (string Line in HTML.Split('¬'))
            {
                if (Line.Length > 20)
                {
                    DLNAService S = new DLNAService(Line);
                    Dic.Add(S.ServiceID, S);
                }
            }
            return(Dic);
        }