IPWorks IoT 2020 JavaScript Edition

Questions / Feedback?

Request Event

Fires when a request is received from a client.


coap.on('Request', listener: (e: {readonly remoteHost: string, readonly remotePort: number, readonly method: number, readonly URIHost: string, readonly URIPort: number, readonly URIPath: string, readonly URIQuery: string, readonly token: string, readonly tokenB: Uint8Array, readonly requestId: string, sendResponse: boolean}) => void )


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 RequestOption*.

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 ResponseOption* 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

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 class-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 class 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 class 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 JavaScript Edition - Version 20.0 [Build 8265]