This class describes the functionality of a CoAP Request as a subclass of a CoAP Message. It provides: 1. operations to answer a request by a response using respond() 2. different ways to handle incoming responses: receiveResponse() or Responsed event
Inheritance: Message
Esempio n. 1
1
        public void TestConfirmable()
        {
            // send request
            Request req2acc = new Request(Method.POST, true);
            req2acc.SetUri("localhost:" + _serverPort + "/" + ACC_RESOURCE);
            req2acc.SetPayload("client says hi");
            req2acc.Send();

            // receive response and check
            Response response = req2acc.WaitForResponse(100);
            Assert.IsNotNull(response);
            Assert.AreEqual(response.PayloadString, SERVER_RESPONSE);
            Assert.AreEqual(response.Type, MessageType.CON);

            Request req2noacc = new Request(Method.POST, true);
            req2noacc.SetUri("coap://localhost:" + _serverPort + "/" + NO_ACC_RESOURCE);
            req2noacc.SetPayload("client says hi");
            req2noacc.Send();

            // receive response and check
            response = req2noacc.WaitForResponse(100);
            Assert.IsNotNull(response);
            Assert.AreEqual(response.PayloadString, SERVER_RESPONSE);
            Assert.AreEqual(response.Type, MessageType.ACK);
        }
Esempio n. 2
0
 /// <summary>
 /// Creates a response to the specified request with the specified response code.
 /// The destination endpoint of the response is the source endpoint of the request.
 /// The response has the same token as the request.
 /// Type and ID are usually set automatically by the <see cref="CoAP.Stack.ReliabilityLayer"/>.
 /// </summary>
 public static Response CreateResponse(Request request, StatusCode code)
 {
     Response response = new Response(code);
     response.Destination = request.Source;
     response.Token = request.Token;
     return response;
 }
Esempio n. 3
0
        public CoapObserveRelation(Request request, IEndPoint endpoint, ICoapConfig config)
        {
            _config = config;
            _request = request;
            _endpoint = endpoint;
            _orderer = new ObserveNotificationOrderer(config);

            request.Reregistering += OnReregister;
        }
Esempio n. 4
0
 /// <summary>
 /// Creates a piggy-backed response with the specified response code
 /// to the specified request.
 /// </summary>
 public static Response CreatePiggybackedResponse(Request request, StatusCode code)
 {
     Response response = new Response(code);
     response.ID = request.ID;
     response.Type = MessageType.ACK;
     response.Destination = request.Source;
     response.Token = request.Token;
     return response;
 }
Esempio n. 5
0
        public static Task <CoAP.Response> SendAsync(this CoAP.Request @this, CoAP.Request request, IEndPoint endPoint)
        {
            var tcs = new TaskCompletionSource <CoAP.Response>();

            request.Respond  += (o, e) => tcs.SetResult(e.Response);
            request.Rejected += (o, e) => tcs.SetException(new CoapRequestException(128));
            request.TimedOut += (o, e) => tcs.SetException(new CoapRequestException(164));
            request.Send(endPoint ?? EndPointManager.Default);

            return(tcs.Task);
        }
 public static BooleanResources Deserialise(Request request)
 {
     BooleanResources result = null;
     string name = request.UriPaths.Last();
     if (!string.IsNullOrEmpty(name) && (request.ContentType == TlvConstant.CONTENT_TYPE_TLV))
     {
         using (TlvReader reader = new TlvReader(request.Payload))
         {
             result = Deserialise(reader);
         }
     }
     return result;
 }
Esempio n. 7
0
 public static OpaqueResource Deserialise(Request request)
 {
     OpaqueResource result = null;
     string name = request.UriPaths.Last();
     if (!string.IsNullOrEmpty(name) && (request.ContentType == TlvConstant.CONTENT_TYPE_TLV))
     {
         OpaqueResource resource = new OpaqueResource(name);
         using (TlvReader reader = new TlvReader(request.Payload))
         {
             if (Deserialise(reader, resource))
                 result = resource;
         }
     }
     return result;
 }
Esempio n. 8
0
        Notification <TPrimitiveContent>?ParseNotification(CoAP.Request request)
        {
            var body = request.PayloadString;

            var notification = DeserializeJson <NotificationContent <TPrimitiveContent> >(body)?.Notification;

            if (notification == null)
            {
                return(null);
            }

            var serializer     = JsonSerializer.CreateDefault(Connection.JsonSettings);
            var representation = ((Newtonsoft.Json.Linq.JObject)notification.NotificationEvent.Representation).ToObject <TPrimitiveContent>(serializer);

            notification.NotificationEvent.PrimitiveRepresentation = representation;

            /*
             * var notificationPrimitive = notification.NotificationEvent.PrimitiveRepresentation = new TPrimitiveContent//new RequestPrimitive<TPrimitiveContent>
             * {
             *      From = request.GetFirstOption((CoAP.OptionType) OneM2mRequestOptions.FR)?.StringValue,
             *      RequestIdentifier = request.GetFirstOption((CoAP.OptionType) OneM2mRequestOptions.RQI)?.StringValue,
             *      //GroupRequestIdentifier = request.GetFirstOption((CoAP.OptionType) OneM2mRequestOptions.GID)?.StringValue,
             *      OriginatingTimestamp = request.GetFirstOption((CoAP.OptionType) OneM2mRequestOptions.OT)?.Value as DateTimeOffset?,
             *      ResultExpirationTimestamp = request.GetFirstOption((CoAP.OptionType) OneM2mRequestOptions.RSET)?.StringValue,
             *      //RequestExpirationTimestamp = request.GetFirstOption((CoAP.OptionType) OneM2mRequestOptions.RQET)?.StringValue,
             *      //OperationExecutionTime = request.GetFirstOption((CoAP.OptionType) OneM2mRequestOptions.OET)?.StringValue,
             *      EventCategory = request.GetFirstOption((CoAP.OptionType) OneM2mRequestOptions.EC)?.StringValue,
             *
             *      PrimitiveContent = representation
             * };
             */

#if false
            var optionNotificationUrl = request.GetFirstOption((CoAP.OptionType)OneM2mRequestOptions.RTURI)?.StringValue;
            if (!string.IsNullOrEmpty(optionNotificationUrl))
            {
                requestPrimitive.ResponseType = new ResponseTypeInfo
                {
                    NotificationURI = optionNotificationUrl.Split('&'),
                    //ResponseTypeValue =
                };
            }
#endif

            //request.SetOption(Option.Create((CoAP.OptionType) OneM2mRequestOptions.RTURI, string.Join("&", body.ResponseType.NotificationURI)));

            return(notification);
        }
Esempio n. 9
0
        public static Task <CoAP.Response> SendTaskAsync(this CoapClient @this, CoAP.Request request)
        {
            var tcs = new TaskCompletionSource <CoAP.Response>();

            @this.SendAsync(request,
                            response =>
            {
                tcs.SetResult(response);
            },
                            failReason =>
            {
                tcs.SetException(new CoapRequestException(failReason == CoapClient.FailReason.Rejected ? 128 : 164));
            }
                            );

            return(tcs.Task);
        }
Esempio n. 10
0
        public async Task <T> GetResponseAsync <T>(CoAP.Request request)
            where T : class, new()
        {
            Trace.WriteLine("\n>>>>>>>>>>>>>>>>");
            Trace.WriteLine($"{request.CodeString} {request.URI}");
            foreach (var option in request.GetOptions())
            {
                Trace.WriteLine($"{option.Name}: ({option.Type}) {option.Value ?? option.StringValue}");
            }
            if (request.PayloadSize > 0)
            {
                Trace.WriteLine(request.PayloadString);
            }
            Trace.WriteLine("");

            var response = await request.SendAsync(request, _pnClient.EndPoint);

            return(await response.DeserializeAsync <T>() ??
                   throw new InvalidDataException("The returned response did not match type 'ResponseContent'"));
        }
Esempio n. 11
0
        private void ProcessRequests()
        {
            while (!_Terminate)
            {
                _TriggerProcessRequests.Reset();
                while (_NewClients.Count > 0)
                {
                    LWM2MClient client = null;
                    try
                    {
                        lock (_NewClients)
                        {
                            if (_NewClients.Count > 0)
                                client = _NewClients.Dequeue();
                        }
                        if (client != null)
                        {
                            if ((client.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) || (client.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6))
                            {
                                Server server = BusinessLogicFactory.Servers.GetServer();
                                System.Net.IPEndPoint ipEndPoint = client.Address as System.Net.IPEndPoint;
                                CoapClient coapClient = new CoapClient();
                                coapClient.EndPoint = client.EndPoint;
                                coapClient.Timeout = REQUEST_TIMEOUT;
                                ushort objectInstanceID = 1;
                                foreach (Model.Security item in server.EndPoints)
                                {
                                    Request request = new Request(Method.PUT);
                                    request.ContentType = TlvConstant.CONTENT_TYPE_TLV;// (int)MediaType.ApplicationOctetStream;
                                    request.Destination = client.Address;
                                    request.UriPath = "/0";
                                    request.Payload = SerialiseObject(item, objectInstanceID);
                                    objectInstanceID++;
                                    coapClient.SendAsync(request, (response) =>
                                        {
                                            if (response != null && response.StatusCode == StatusCode.Changed)
                                            {
                                                request = new Request(Method.PUT);
                                                request.ContentType = TlvConstant.CONTENT_TYPE_TLV;//(int)MediaType.ApplicationOctetStream;
                                                request.Destination = client.Address;
                                                request.UriPath = "/1";
                                                request.Payload = SerialiseObject(server, 1);
                                                coapClient.SendAsync(request, (response2) =>
                                                    {
                                                        if (response2 != null && response2.StatusCode == StatusCode.Changed)
                                                        {
                                                            request = new Request(Method.POST);
                                                            request.Destination = client.Address;
                                                            request.UriPath = "/bs";
                                                            coapClient.SendAsync(request);
                                                        }
                                                    });
                                            }
                                        }
                                    );
                                }

                            }
                        }
                    }
                    catch(Exception ex)
                    {
                        ApplicationEventLog.WriteEntry("Flow", ex.ToString(), System.Diagnostics.EventLogEntryType.Error);
                    }
                }
                if (!_Terminate)
                    _TriggerProcessRequests.WaitOne();
            }
        }
Esempio n. 12
0
        private CoapObserveRelation ObserveAsync(Request request, Action<Response> notify, Action<FailReason> error)
        {
            IEndPoint endpoint = GetEffectiveEndpoint(request);
            ObserveNotificationOrderer orderer = new ObserveNotificationOrderer(_config);
            CoapObserveRelation relation = new CoapObserveRelation(request, endpoint);

            request.Respond += (o, e) =>
            {
                Response resp = e.Response;
                lock (orderer)
                {
                    if (orderer.IsNew(resp))
                    {
                        relation.Current = resp;
                        Deliver(notify, e);
                    }
                    else
                    {
                        if (log.IsDebugEnabled)
                            log.Debug("Dropping old notification: " + resp);
                    }
                }
            };
            Action<FailReason> fail = r =>
            {
                relation.Canceled = true;
                Fail(error, r);
            };
            request.Reject += (o, e) => fail(FailReason.Rejected);
            request.Timeout += (o, e) => fail(FailReason.TimedOut);

            Prepare(request, endpoint).Send();
            return relation;
        }
Esempio n. 13
0
        internal CoAP.Request GetRequest(RequestPrimitive <TPrimitiveContent> body)
        {
            var args = GetRequestParameters(body);

            var fc = body.FilterCriteria;

            if (fc != null)
            {
                if (fc.Attribute != null)
                {
                    foreach (var attr in fc.Attribute)
                    {
                        if (attr.Value != null)
                        {
                            args.Add("atr", $"{attr.Name},{attr.Value.ToString()}");
                        }
                    }
                }
            }

            var method = body.Operation switch
            {
                Operation.Retrieve => CoAP.Method.GET,
                Operation.Update => CoAP.Method.PUT,
                Operation.Delete => CoAP.Method.DELETE,
                _ => CoAP.Method.POST,
            };

            var request = new CoAP.Request(method);

            request.AckTimeout = 10000 * 1000;

            request.URI = _pnClient.Uri;
            var to        = body.To;
            var pathParts = to.Split("/", StringSplitOptions.RemoveEmptyEntries);

            if (to.StartsWith("//"))
            {
                request.AddUriPath("_");
            }
            else if (to.StartsWith("/"))
            {
                request.AddUriPath("~");
            }

            foreach (var pathPart in pathParts)
            {
                request.AddUriPath(pathPart);
            }

            foreach (var query in args.AllKeys.SelectMany(args.GetValues, (k, v) => $"{k}={/*Uri.EscapeDataString*/(v)}"))
            {
                request.AddUriQuery(query);
            }

            if (body.ResourceType != null)
            {
                request.AddOption(Option.Create((CoAP.OptionType)OneM2mRequestOptions.TY, (int)body.ResourceType));
            }

            if (body.PrimitiveContent != null)
            {
                var bodyJson = SerializeJson(body.PrimitiveContent);
                request.SetPayload(bodyJson, (int)ContentFormats.Json);
            }

            if (body.From != null)
            {
                request.SetOption(Option.Create((CoAP.OptionType)OneM2mRequestOptions.FR, body.From));
            }

            request.SetOption(Option.Create((CoAP.OptionType)OneM2mRequestOptions.RQI, body.RequestIdentifier ?? NextRequestId));

            if (body.GroupRequestIdentifier != null)
            {
                request.SetOption(Option.Create((CoAP.OptionType)OneM2mRequestOptions.GID, body.GroupRequestIdentifier));
            }

            if (body.OriginatingTimestamp != null)
            {
                request.SetOption(Option.Create((CoAP.OptionType)OneM2mRequestOptions.OT, body.OriginatingTimestamp.Value.ToString(_dateTimeFormat)));
            }

            if (body.ResultExpirationTimestamp != null)
            {
                request.SetOption(Option.Create((CoAP.OptionType)OneM2mRequestOptions.RSET, body.ResultExpirationTimestamp));
            }

            if (body.RequestExpirationTimestamp != null)
            {
                request.SetOption(Option.Create((CoAP.OptionType)OneM2mRequestOptions.RQET, body.RequestExpirationTimestamp));
            }

            if (body.OperationExecutionTime != null)
            {
                request.SetOption(Option.Create((CoAP.OptionType)OneM2mRequestOptions.OET, body.OperationExecutionTime));
            }

            if (body.EventCategory != null)
            {
                request.SetOption(Option.Create((CoAP.OptionType)OneM2mRequestOptions.EC, body.EventCategory));
            }

            if (body.ResponseType?.NotificationURI != null)
            {
                request.SetOption(Option.Create((CoAP.OptionType)OneM2mRequestOptions.RTURI, string.Join("&", body.ResponseType.NotificationURI)));
            }

            return(request);
        }
Esempio n. 14
0
 static Request Accept(Request request, Int32 accept)
 {
     request.Accept = accept;
     return request;
 }
Esempio n. 15
0
 internal CoapObserveRelation(Request request, IEndPoint endpoint)
 {
     _request = request;
     _endpoint = endpoint;
 }
Esempio n. 16
0
 /// <summary>
 /// Gets the effective endpoint that the specified request
 /// is supposed to be sent over.
 /// </summary>
 protected IEndPoint GetEffectiveEndpoint(Request request)
 {
     if (_endpoint != null)
         return _endpoint;
     else
         return EndPointManager.Default;
     // TODO secure coap
 }
Esempio n. 17
0
 static Request ETags(Request request, params Byte[][] etags)
 {
     foreach (Byte[] etag in etags)
     {
         request.AddETag(etag);
     }
     return request;
 }
Esempio n. 18
0
 static Request IfMatch(Request request, params Byte[][] etags)
 {
     foreach (Byte[] etag in etags)
     {
         request.AddIfMatch(etag);
     }
     return request;
 }
Esempio n. 19
0
 public async Task <ResponseContent <TPrimitiveContent> > GetResponseAsync(CoAP.Request request) => await GetResponseAsync <ResponseContent <TPrimitiveContent> >(request);
Esempio n. 20
0
 public Request NewPutRequest(ObjectType objectType, string instanceID, string resourceID, int contentType, byte[] data)
 {
     Request result = new Request(Method.PUT);
     //if (contentType == MediaType.TextPlain)
     //    contentType = TlvConstant.CONTENT_TYPE_PLAIN;
     SetupRequest(result, objectType, instanceID, resourceID);
     result.Payload = data;
     if (contentType != -1)
         result.ContentType = contentType;
     return result;
 }
Esempio n. 21
0
 public Request NewPostRequest(ObjectType objectType, string instanceID, string resourceID, int contentType, byte[] data)
 {
     Request result = new Request(Method.POST);
     SetupRequest(result, objectType, instanceID, resourceID);
     result.Payload = data;
     if (contentType != -1)
         result.ContentType = contentType;
     return result;
 }
Esempio n. 22
0
 public Request NewGetRequest(ObjectType objectType, string instanceID, string resourceID)
 {
     Request result = new Request(Method.GET);
     //result.Accept = TlvConstant.CONTENT_TYPE_TLV;
     result.Accept = _DataFormat;
     //if (_DataFormat == MediaType.TextPlain)
     //    result.Accept = TlvConstant.CONTENT_TYPE_PLAIN;
     SetupRequest(result, objectType, instanceID, resourceID);
     return result;
 }
Esempio n. 23
0
 public Request NewGetRequest(ObjectType objectType, string instanceID)
 {
     Request result = new Request(Method.GET);
     //result.Accept = TlvConstant.CONTENT_TYPE_TLV;
     result.Accept = _DataFormat;
     SetupRequest(result, objectType, instanceID, null);
     return result;
 }
Esempio n. 24
0
 public Request NewDeleteRequest(ObjectType objectType, string instanceID, string resourceID)
 {
     Request result = new Request(Method.DELETE);
     SetupRequest(result, objectType, instanceID, resourceID);
     return result;
 }
Esempio n. 25
0
 private CoapObserveRelation Observe(Request request, Action<Response> notify, Action<FailReason> error)
 {
     CoapObserveRelation relation = ObserveAsync(request, notify, error);
     Response response = relation.Request.WaitForResponse(_timeout);
     if (response == null || !response.HasOption(OptionType.Observe))
         relation.Canceled = true;
     relation.Current = response;
     return relation;
 }
Esempio n. 26
0
        //System.Net.IPAddress.Parse("fe80::18be:e89d:e85f:278%12") //15685
        public bool Bootstrap(string url)
        {
            bool result = false;
            _Timer.Stop();
            Uri uri = new Uri(url);
            foreach (System.Net.IPAddress address in System.Net.Dns.GetHostAddresses(uri.DnsSafeHost))
            {
                CoapClient coapClient = new CoapClient();
                coapClient.EndPoint = _EndPoint;
                Request request = new Request(Method.POST);
                int port = 5683;
                if (string.Compare(uri.Scheme, "coaps", true) ==0)
                    port = 5684;
                if (uri.Port > 0)
                    port = uri.Port;
                request.Destination = new System.Net.IPEndPoint(address, port);
                request.UriPath = "/bs";
                request.UriQuery = "ep=test";
                Response response = coapClient.Send(request);
                if (response != null && response.StatusCode == StatusCode.Changed)
                {
                    result = _BootsrapComplete.Wait(30000);
                    break;
                }
            }

            return result;
        }
Esempio n. 27
0
 public void Disconnect()
 {
     if (!string.IsNullOrEmpty(_Location))
     {
         CoapClient coapClient = new CoapClient();
         coapClient.EndPoint = _EndPoint;
         Request request = new Request(Method.DELETE);
         request.Destination = _ServerEndPoint;
         request.UriPath = _Location;
         coapClient.SendAsync(request);
         _Location = null;
     }
 }
Esempio n. 28
0
        protected Request Prepare(Request request, IEndPoint endpoint)
        {
            request.Type = _type;
            request.URI = _uri;
            
            if (_blockwise != 0)
                request.SetBlock2(BlockOption.EncodeSZX(_blockwise), false, 0);

            if (endpoint != null)
                request.EndPoint = endpoint;

            return request;
        }
Esempio n. 29
0
 public Request SendRequest(Request request)
 {
     request.Respond += new EventHandler<ResponseEventArgs>(UpdateMetrics);
     return request.Send();
 }
Esempio n. 30
0
 static Request IfNoneMatch(Request request)
 {
     request.IfNoneMatch = true;
     return request;
 }
 public static LWM2MAccessControlResource Deserialise(Request request)
 {
     LWM2MAccessControlResource result = null;
     string name = request.UriPaths.Last();
     if (!string.IsNullOrEmpty(name) && (request.ContentType == TlvConstant.CONTENT_TYPE_TLV))
     {
         result = new LWM2MAccessControlResource(name);
         using (TlvReader reader = new TlvReader(request.Payload))
         {
             result.Deserialise(reader);
         }
     }
     return result;
 }
Esempio n. 32
0
 private void SetupRequest(Request request, ObjectType objectType, string instanceID, string resourceID)
 {
     request.Destination = this.Address;
     request.EndPoint = this.EndPoint;
     if (string.IsNullOrEmpty(instanceID))
         request.UriPath = objectType.Path;
     else if (string.IsNullOrEmpty(resourceID))
         request.UriPath = string.Concat(objectType.Path, "/", instanceID);
     else
         request.UriPath = string.Concat(objectType.Path, "/", instanceID, "/", resourceID);
 }
Esempio n. 33
0
        public bool ConnectToServer()
        {
            bool result = false;
            //now register to server
            foreach (SecurityResource item in _SecurityResources.Children)
            {
                Console.Write(item.ServerURI);
                Console.Write(") .. ");
                Uri uri = new Uri(item.ServerURI);
                foreach (System.Net.IPAddress address in System.Net.Dns.GetHostAddresses(uri.DnsSafeHost))
                {
                    bool secure =false;
                    int port = 5683;
                    if (string.Compare(uri.Scheme, "coaps", true) == 0)
                    {
                        secure = true;
                        port = 5684;
                    }
                    if (uri.Port > 0)
                        port = uri.Port;
                    if (_Channel.Secure != secure)
                    {
                        _Channel.Stop();
                        _Channel.Secure = secure;
                        _Channel.Start();
                    }
                    CoapClient coapClient = new CoapClient();
                    coapClient.EndPoint = _EndPoint;
                    Request request = new Request(Method.POST);
                    request.Destination = new System.Net.IPEndPoint(address, port);
                    request.UriPath = "/rd";
                    request.UriQuery = string.Concat("ep=test",Environment.MachineName,"&lt=35");
                    StringBuilder payLoad = new StringBuilder();
                    foreach (IResource objectType in _Root.Children)
                    {
                        if (objectType.Visible)
                        {
                            bool instances = false;
                            foreach (IResource instance in objectType.Children)
                            {
                                if (payLoad.Length > 0)
                                    payLoad.Append(',');
                                payLoad.Append('<');
                                payLoad.Append('/');
                                payLoad.Append(objectType.Name);
                                payLoad.Append('/');
                                payLoad.Append(instance.Name);
                                payLoad.Append('>');
                                instances = true;
                            }
                            if (!instances)
                            {
                                if (payLoad.Length > 0)
                                    payLoad.Append(',');
                                payLoad.Append('<');
                                payLoad.Append('/');
                                payLoad.Append(objectType.Name);
                                payLoad.Append('>');
                            }
                        }
                    }
                    request.PayloadString = payLoad.ToString();
                    request.ContentType = (int)MediaType.ApplicationLinkFormat;
                    Response response = coapClient.Send(request);
                    if (response != null && response.StatusCode == StatusCode.Created)
                    {
                        string location = response.LocationPath;

                        int position = location.LastIndexOf('/');
                        if (position > 0)
                        {
                            ClientID = location.Substring(position + 1);
                        }

                        result = true;
                        _ServerEndPoint = request.Destination;
                        _Location = location;
                        _Timer.Start();
                        break;
                    }
                }
            }
            return result;
        }
Esempio n. 34
0
        public void CancelObserve(ObjectType objectType, string instanceID, string resourceID, bool useReset)
        {
            if (_ObserveRequests != null)
            {
                string uriPath;
                if (string.IsNullOrEmpty(instanceID))
                    uriPath = objectType.Path;
                else if (string.IsNullOrEmpty(resourceID))
                    uriPath = string.Concat(objectType.Path, "/", instanceID);
                else
                    uriPath = string.Concat(objectType.Path, "/", instanceID, "/", resourceID);
                int index = 0;
                while (index < _ObserveRequests.Count)
                {
                    if (_ObserveRequests[index].Request.UriPath == uriPath)
                    {
                        Request observeRequest = _ObserveRequests[index].Request;
                        _ObserveRequests.RemoveAt(index);
                        if (observeRequest != null)
                        {
                            if (useReset)
                            {
                                observeRequest.IsCancelled = true;
                            }
                            else
                            {
                                Request request = new Request(Method.GET);
                                request.Accept = _DataFormat;
                                request.Destination = observeRequest.Destination;
                                request.EndPoint = observeRequest.EndPoint;
                                request.UriPath = observeRequest.UriPath;
                                request.MarkObserveCancel();
                                SendRequest(request);
                                observeRequest.IsCancelled = true;
                            }
                        }

                    }
                    else
                        index++;
                }
            }
        }
Esempio n. 35
0
 private void SendUpdate()
 {
     if (!string.IsNullOrEmpty(_Location))
     {
         CoapClient coapClient = new CoapClient();
         coapClient.EndPoint = _EndPoint;
         Request request = new Request(Method.PUT);
         request.Destination = _ServerEndPoint;
         request.UriPath = _Location;
         request.UriQuery = "lt=35";
         coapClient.SendAsync(request);
     }
 }
Esempio n. 36
-1
 protected Request Prepare(Request request)
 {
     return Prepare(request, GetEffectiveEndpoint(request));
 }