Exemplo n.º 1
0
        public bool IsNoResponse(NoResponseType?messageNrt, NoResponseType result)
        {
            if (!messageNrt.HasValue)
            {
                return(false);
            }

            return(messageNrt.Value.HasFlag(result));
        }
Exemplo n.º 2
0
        public async Task UnsubscribeAsync(string resourceUriString, NoResponseType nrt)
        {
            if (!channel.IsConnected)
            {
                await ConnectAsync();
            }

            session.UpdateKeepAliveTimestamp();

            byte[]      token         = CoapToken.Create().TokenBytes;
            ushort      id            = session.CoapSender.NewId(token);
            string      scheme        = channel.IsEncrypted ? "coaps" : "coap";
            string      coapUriString = GetCoapUriString(scheme, config.Authority, resourceUriString);
            CoapRequest cr            = new CoapRequest(id, RequestMessageType.NonConfirmable, MethodType.DELETE, token, new Uri(coapUriString), null);

            cr.NoResponse = nrt;
            await channel.SendAsync(cr.Encode());
        }
Exemplo n.º 3
0
        public Task PublishAsync(string resourceUriString, string contentType, byte[] payload, NoResponseType nrt)
        {
            if (!channel.IsConnected)
            {
                Open();
                Receive();
            }

            session.UpdateKeepAliveTimestamp();

            byte[] token         = CoapToken.Create().TokenBytes;
            ushort id            = session.CoapSender.NewId(token);
            string scheme        = channel.IsEncrypted ? "coaps" : "coap";
            string coapUriString = GetCoapUriString(scheme, resourceUriString);

            CoapRequest cr = new CoapRequest(id, RequestMessageType.NonConfirmable, MethodType.POST,
                                             new Uri(coapUriString), MediaTypeConverter.ConvertToMediaType(contentType), payload)
            {
                NoResponse = nrt
            };

            return(channel.SendAsync(cr.Encode()));
        }