Send() public method

Sends this message.
public Send ( ) : Request
return Request
コード例 #1
1
ファイル: MessageTypeTest.cs プロジェクト: rlusian1/CoAP.NET
        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);
        }
コード例 #2
1
        private void ExecutePOSTRequest()
        {
            String payload = "--no payload--";
            try
            {
                Request request = new Request(Method.POST);
                request.SetUri("coap://localhost:" + _serverPort + "/" + request_short + respond_short);
                if (request_short)
                    request.SetPayload(SHORT_POST_REQUEST);
                else
                    request.SetPayload(LONG_POST_REQUEST);
                request.Send(_clientEndpoint);

                // receive response and check
                Response response = request.WaitForResponse(1000);

                Assert.IsNotNull(response);
                payload = response.PayloadString;

                if (respond_short)
                    Assert.AreEqual(SHORT_POST_RESPONSE, payload);
                else 
                    Assert.AreEqual(LONG_POST_RESPONSE, payload);
            }
            finally
            {
                Thread.Sleep(100); // Quickly wait until last ACKs arrive
            }
        }
コード例 #3
0
        private void SendRequestAndExpect(String expected)
        {
            Thread.Sleep(100);
            Request request = Request.NewGet();

            request.SetUri("localhost:" + _serverPort + "/ress");
            String response = request.Send().WaitForResponse(1000).PayloadString;

            Assert.AreEqual(expected, response);
        }
コード例 #4
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);
        }
コード例 #5
0
ファイル: CoapClient.cs プロジェクト: zpfcaca/CoAP.NET
 /// <summary>
 /// Performs a CoAP ping and gives up after the given number of milliseconds.
 /// </summary>
 /// <param name="timeout">the time to wait for a pong in milliseconds</param>
 /// <returns>success of the ping</returns>
 public Boolean Ping(Int32 timeout)
 {
     try
     {
         Request request = new Request(Code.Empty, true);
         request.Token = CoapConstants.EmptyToken;
         request.URI   = Uri;
         request.Send().WaitForResponse(timeout);
         return(request.IsRejected);
     }
     catch (System.Threading.ThreadInterruptedException)
     {
         /* ignore */
     }
     return(false);
 }
コード例 #6
0
        private void TestSimpleNONGet(Uri uri)
        {
            Console.WriteLine("Test simple NON GET to " + uri);

            Request request = Request.NewGet();

            request.URI  = uri;
            request.Type = MessageType.NON;
            Response response = request.Send(_clientEndpoint).WaitForResponse(1000);

            Console.WriteLine("Client received response " + response.PayloadString + " with msg type " + response.Type);
            Assert.AreEqual(_currentResponseText, response.PayloadString);
            Assert.AreEqual(MessageType.NON, response.Type);

            _serverSurveillant.WaitUntilDeduplicatorShouldBeEmpty();
            _serverSurveillant.AssertMapsEmpty();
            _clientSurveillant.AssertMapsEmpty();
        }
コード例 #7
0
        public void ProactiveCancel()
        {
            Request cancel = Request.NewGet();

            // copy options, but set Observe to cancel
            cancel.SetOptions(_request.GetOptions());
            cancel.MarkObserveCancel();
            // use same Token
            cancel.Token       = _request.Token;
            cancel.Destination = _request.Destination;

            // dispatch final response to the same message observers
            cancel.CopyEventHandler(_request);

            cancel.Send(_endpoint);
            // cancel old ongoing request
            _request.IsCancelled = true;
            _canceled            = true;
        }
コード例 #8
0
        private void ExecutePOSTRequest()
        {
            String payload = "--no payload--";

            try
            {
                Request request = new Request(Method.POST);
                request.SetUri("coap://localhost:" + _serverPort + "/" + request_short + respond_short);
                if (request_short)
                {
                    request.SetPayload(SHORT_POST_REQUEST);
                }
                else
                {
                    request.SetPayload(LONG_POST_REQUEST);
                }
                request.Send(_clientEndpoint);

                // receive response and check
                Response response = request.WaitForResponse(1000);

                Assert.IsNotNull(response);
                payload = response.PayloadString;

                if (respond_short)
                {
                    Assert.AreEqual(SHORT_POST_RESPONSE, payload);
                }
                else
                {
                    Assert.AreEqual(LONG_POST_RESPONSE, payload);
                }
            }
            finally
            {
                Thread.Sleep(100); // Quickly wait until last ACKs arrive
            }
        }
コード例 #9
0
ファイル: Client.cs プロジェクト: CreatorDev/DeviceServer
 public Request SendRequest(Request request)
 {
     request.Respond += new EventHandler<ResponseEventArgs>(UpdateMetrics);
     return request.Send();
 }
コード例 #10
0
ファイル: CoapClient.cs プロジェクト: rlusian1/CoAP.NET
 /// <summary>
 /// Performs a CoAP ping and gives up after the given number of milliseconds.
 /// </summary>
 /// <param name="timeout">the time to wait for a pong in milliseconds</param>
 /// <returns>success of the ping</returns>
 public Boolean Ping(Int32 timeout)
 {
     try
     {
         Request request = new Request(Code.Empty, true);
         request.Token = CoapConstants.EmptyToken;
         request.URI = Uri;
         request.Send().WaitForResponse(timeout);
         request.IsCancelled = true;
         return request.IsRejected;
     }
     catch (System.Threading.ThreadInterruptedException)
     {
         /* ignore */
     }
     return false;
 }