Exemplo n.º 1
0
        public void Encode_And_Decode_Payload_Length_12()
        {
            var optionBuilder = new CoapMessageOptionFactory();

            var message = new CoapMessage
            {
                Type    = CoapMessageType.Confirmable,
                Code    = CoapMessageCodes.Put,
                Id      = ushort.MaxValue,
                Payload = Encoding.UTF8.GetBytes("123456789012")
            };

            message.Options = new List <CoapMessageOption>
            {
                optionBuilder.CreateUriPort(5648)
            };

            Enocde_And_Decode_Internal(message);
        }
Exemplo n.º 2
0
        public void Encode_And_Decode_No_Token()
        {
            var optionBuilder = new CoapMessageOptionFactory();

            var message = new CoapMessage
            {
                Type    = CoapMessageType.NonConfirmable,
                Code    = CoapMessageCodes.Put,
                Id      = 0x5876,
                Token   = null,
                Payload = null
            };

            message.Options = new List <CoapMessageOption>
            {
                optionBuilder.CreateUriPort(66000)
            };

            Enocde_And_Decode_Internal(message);
        }
Exemplo n.º 3
0
        public void Encode_And_Decode_No_Payload()
        {
            var optionBuilder = new CoapMessageOptionFactory();

            var message = new CoapMessage
            {
                Type    = CoapMessageType.Acknowledgement,
                Code    = CoapMessageCodes.Get,
                Id      = 0x5876,
                Token   = new byte[] { 1, 2, 3, 4 },
                Payload = null
            };

            message.Options = new List <CoapMessageOption>
            {
                optionBuilder.CreateUriPort(50)
            };

            Enocde_And_Decode_Internal(message);
        }
Exemplo n.º 4
0
        public void Encode_And_Decode_Full()
        {
            var optionBuilder = new CoapMessageOptionFactory();

            var message = new CoapMessage
            {
                Type    = CoapMessageType.Confirmable,
                Code    = CoapMessageCodes.Post,
                Id      = 0x5876,
                Token   = new byte[] { 1, 2, 3, 4 },
                Payload = Encoding.UTF8.GetBytes("payloadOver13chars")
            };

            message.Options = new List <CoapMessageOption>
            {
                optionBuilder.CreateUriPort(5648)
            };

            Enocde_And_Decode_Internal(message);
        }
Exemplo n.º 5
0
        public void Encode_And_Decode_Multiple_Uri_Path()
        {
            var optionBuilder = new CoapMessageOptionFactory();

            var message = new CoapMessage
            {
                Type    = CoapMessageType.Acknowledgement,
                Code    = CoapMessageCodes.Delete,
                Id      = 0x50,
                Token   = null,
                Payload = null
            };

            message.Options = new List <CoapMessageOption>
            {
                optionBuilder.CreateUriPath("a"),
                optionBuilder.CreateUriPath("b"),
                optionBuilder.CreateUriPath("c")
            };

            Enocde_And_Decode_Internal(message);
        }
Exemplo n.º 6
0
        public void Encode_Simple_Get_Request()
        {
            var expected      = Convert.FromBase64String("QAHLDnIWEP9wYXlsb2Fk");
            var optionBuilder = new CoapMessageOptionFactory();

            var message = new CoapMessage
            {
                Type    = CoapMessageType.Confirmable,
                Code    = CoapMessageCodes.Get,
                Id      = 0xcb0e,
                Payload = Encoding.UTF8.GetBytes("payload")
            };

            message.Options = new List <CoapMessageOption>
            {
                optionBuilder.CreateUriPort(5648)
            };

            var messageEncoder = new CoapMessageEncoder();
            var messageBuffer  = messageEncoder.Encode(message);

            AssertDataIsEqual(expected, messageBuffer.ToArray());
        }
Exemplo n.º 7
0
        static async Task Main()
        {
            var optionBuilder = new CoapMessageOptionFactory();

            var coapClient = new CoapFactory().CreateClient();

            Console.WriteLine("CONNECTING...");

            var request = new CoapRequest
            {
                Method = CoapRequestMethod.Get,
                Uri    = "15001"
            };

            await coapClient.ConnectAsync(new CoapClientConnectOptions
            {
                Host           = "192.168.1.228",
                Port           = 5684,
                TransportLayer = new UdpWithDtlsCoapTransportLayer()
                {
                    Credentials = new PreSharedKey
                    {
                        Identity = Encoding.ASCII.GetBytes("IDENTITY"),
                        Key      = Encoding.ASCII.GetBytes("lqxbBH6o2eAKSo5A")
                    }
                }
            }, CancellationToken.None);

            var response = await coapClient.Request(request, CancellationToken.None);

            Console.WriteLine("DATA RECEIVED");

            Console.WriteLine("Code = " + response.StatusCode);
            Console.WriteLine("Payload = " + Encoding.ASCII.GetString(response.Payload.ToArray()));

            Console.ReadLine();
        }