Request Event

Fires when a request is received from a client.

Syntax

public event OnRequestHandler OnRequest;

public delegate void OnRequestHandler(object sender, CoapRequestEventArgs e);

public class CoapRequestEventArgs : EventArgs {
  public string RemoteHost { get; }
  public int RemotePort { get; }
  public int Method { get; }
  public string URIHost { get; }
  public int URIPort { get; }
  public string URIPath { get; }
  public string URIQuery { get; }
  public string Token { get; }
public byte[] TokenB { get; } public string RequestId { get; } public bool SendResponse { get; set; } }
Public Event OnRequest As OnRequestHandler

Public Delegate Sub OnRequestHandler(sender As Object, e As CoapRequestEventArgs)

Public Class CoapRequestEventArgs Inherits EventArgs
  Public ReadOnly Property RemoteHost As String
  Public ReadOnly Property RemotePort As Integer
  Public ReadOnly Property Method As Integer
  Public ReadOnly Property URIHost As String
  Public ReadOnly Property URIPort As Integer
  Public ReadOnly Property URIPath As String
  Public ReadOnly Property URIQuery As String
  Public ReadOnly Property Token As String
Public ReadOnly Property TokenB As Byte() Public ReadOnly Property RequestId As String Public Property SendResponse As Boolean End Class

Remarks

This event fires anytime a request is received from a client. Information about the request is exposed both via this event's parameters and the following properties: RequestData, RequestContentFormat, RequestETag, and RequestOptions.

A response can either be sent back to the client immediately when the event finishes, or later using the SendResponse method. Refer to the RequestId and SendResponse parameters' documentation, below, for more information. If a response is to be sent back immediately, populate the ResponseCode, ResponseData, ResponseContentFormat, ResponseETag, and ResponseOptions properties as desired before this event finishes.

The RemoteHost parameter reflects the client's IP address or hostname.

The RemotePort parameter reflects the client's port.

The Method parameter reflects the request method code. The following table provides a (non-exhaustive) list of some of the more common method codes; refer to the IANA's CoAP Method Codes registry for a full list.

Method Code Name
1 GET
2 POST
3 PUT
4 DELETE
5 FETCH
6 PATCH

The URIHost, URIPort, URIPath, and URIQuery parameters, when taken together, identify the resource that the client is making a request against. This event exposes the URI in pieces for convenience.

The Token parameter reflects the token included in the request.

The RequestId parameter reflects the component-generated Id for the request. If the final value of the SendResponse parameter is False, this Id can be passed to the SendResponse method later to send a response. (Alternatively, it can be passed to the CancelRequest later to ignore the request.)

The SendResponse parameter specifies whether the component should send a response back to the client immediately; it is True by default. Set it to False to send the response later instead.

Note: This event is only used when the component is operating in server mode (i.e., when the Listening property is enabled).

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks IoT 2020 .NET Edition - Version 20.0 [Build 8265]