Beispiel #1
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;
     }
 }
Beispiel #2
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);
     }
 }
Beispiel #3
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();
            }
        }