コード例 #1
0
ファイル: SsdpDevice.cs プロジェクト: valoni/NETMF-Toolkit
        internal string ToSoapMessage()
        {
            string xml = string.Format(@"<?xml version=""1.0""?>
<root xmlns=""urn:schemas-upnp-org:device-1-0"">
    <specVersion>
		<major>1</major>
		<minor>0</minor>
	</specVersion>
    <device>
        <deviceType>{0}</deviceType>
        <friendlyName>{1}</friendlyName>
        <manufacturer/>
        <manufacturerURL/>
        <modelDescription/>
        <modelName/>
        <modelNumber/>
        <modelURL/>
        <UDN>{2}</UDN>
        <iconList/>
        <serviceList>
            <service>
				<serviceType>urn:schemas-any-com:service:Any:1</serviceType>
				<serviceId>urn:any-com:serviceId:any1</serviceId>
				<controlURL>/upnp/control/any</controlURL>
				<eventSubURL>/upnp/control/any</eventSubURL>
				<SCPDURL>/any.xml</SCPDURL>
			</service>
        </serviceList>
        <deviceList/>
        <presentationURL>{3}</presentationURL>
    </device>
</root>", DeviceTypeHelper.GetDeviceType(Type), Name, UDN, PresentationURL.ToString());

            return(xml);
        }
コード例 #2
0
ファイル: SsdpServer.cs プロジェクト: valoni/NETMF-Toolkit
        internal void NotifyDevice(SsdpDevice device, bool isAlive)
        {
            /*
             * NOTIFY * HTTP/1.1
             * HOST: 239.255.255.250:1900
             * LOCATION: http://192.168.178.1:49000/igddesc.xml
             * SERVER: Interactive UPnP/1.0 AVM FRITZ!Box Fon WLAN 7270 54.04.70
             * CACHE-CONTROL: max-age=60
             * NT: urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1
             * NTS: ssdp:alive
             * USN: uuid:75802409-bccb-40e7-8e6b-001F3FF667FC::urn:schemas-upnp-org:service:WAN
             */


            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1);
            s.ReceiveTimeout = 100;

            List <string> res = new List <string>();

            foreach (String address in _broadcastAddresses)
            {
                string req = string.Format(@"NOTIFY * HTTP/1.1
HOST: {0}:1900
LOCATION: http://{1}:{2}/igddesc.xml/{3}
SERVER: {5} UPnP/1.0 MFToolkit
CACHE-CONTROL: max-age=60
NT: upnp:rootdevice
NTS: ssdp:{6}
USN: {3}::upnp:rootdevice

",
                                           address,
                                           _http.Address.ToString(),
                                           _http.Port,
                                           device.UDN,
                                           DeviceTypeHelper.GetDeviceType(device.Type),
                                           device.Name,
                                           (isAlive ? "alive" : "byebye"));

                byte[] data   = Encoding.ASCII.GetBytes(req);
                byte[] buffer = new byte[1024];

                for (int i = 0; i < 3; i++)
                {
                    try
                    {
                        Console.WriteLine("Sending ssdp:" + (isAlive ? "alive" : "byebye") + " for " + device.Name + " (" + device.UDN + ")...");

                        s.SendTo(data, new IPEndPoint(IPAddress.Broadcast, 1900));
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }