Exemplo n.º 1
0
        private async Task <uint> SendSearchDevicesRequest(SsdpMessage request, CancellationToken token)
        {
            token.ThrowIfCancellationRequested();
            var outputStream = await unicastLocalSocket.GetOutputStreamAsync(Constants.SSDP_HOST, Constants.SSDP_PORT);

            var writer = new DataWriter(outputStream);

            writer.WriteString(request.ToString());
            return(await writer.StoreAsync());
        }
Exemplo n.º 2
0
        private async Task RespondToSearch(HostName host, string port)
        {
            SsdpMessage searchResponse = new SsdpMessage
            {
                Type              = SsdpMessageType.SearchResponse,
                CacheControl      = "max-age = 30",
                Date              = DateTimeOffset.UtcNow,
                Server            = Name,
                ST                = Target,
                USN               = USN,
                AdditionalHeaders = new Dictionary <string, string> {
                    { "PORT", Port.ToString() }
                },
            };

            var unicastSocket = new DatagramSocket();
            var outputStream  = await unicastSocket.GetOutputStreamAsync(host, port);

            var writer = new DataWriter(outputStream);

            writer.WriteString(searchResponse.ToString());
            await writer.StoreAsync();
        }
Exemplo n.º 3
0
        public IAsyncOperation <uint> AdvertiseByeBye()
        {
            return(Task.Run(async() =>
            {
                SsdpMessage request = new SsdpMessage
                {
                    Type = SsdpMessageType.AdvertiseByeBye,
                    Host = Constants.SSDP_ADDRESS,
                    NT = Target,
                    NTS = "ssdp:byebye",
                    Server = Name,
                    USN = USN,
                    AdditionalHeaders = new Dictionary <string, string> {
                        { "PORT", Port.ToString() }
                    },
                };

                var outputStream = await multicastSsdpSocket.GetOutputStreamAsync(Constants.SSDP_HOST, Constants.SSDP_PORT);
                var writer = new DataWriter(outputStream);
                writer.WriteString(request.ToString());
                return await writer.StoreAsync();
            }).AsAsyncOperation());
        }