IPWorks IoT 2020 Kotlin Edition

Questions / Feedback?

Request Event

Fires when a request is received from a client.

Syntax

public open class DefaultCoapEventListener : CoapEventListener {
  ...
  public override fun request(e: CoapRequestEvent) {}
  ...
}

public class CoapRequestEvent {
  val remoteHost: String?
  val remotePort: Int
  val method: Int
  val uriHost: String?
  val uriPort: Int
  val uriPath: String?
  val uriQuery: String?
  val token: ByteArray?
  val requestId: String?
  var sendResponse: Boolean
}

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) 2021 /n software inc. - All rights reserved.
IPWorks IoT 2020 Kotlin Edition - Version 20.0 [Build 7941]