The QCoapClient class contains signals that get triggered when the reply of a sent request has arrived.
The application can use a QCoapClient to send requests over a CoAP network. It provides functions for standard requests: each returns a QCoapReply object, to which the response data shall be delivered; this can be read when the finished() signal arrives.
A simple request can be sent with:
QCoapClient *client = new QCoapClient(this);
connect(client, &QCoapClient::finished, this, &TestClass::slotFinished);
client->get(QCoapRequest(Qurl("coap://coap.me/test")));
You can also use an observe request. This can be used as above, or more conveniently with the QCoapReply::notified() signal:
The default value is an invalid QNetworkInterface object, meaning that incoming packets will be accepted from all network interfaces. Similarly, all network interfaces can be used to send outgoing packets.
When a valid network interface is specified, incoming packets will only be accepted from that interface. Similarly, outgoing packets will only be sent using that interface.
Changing the property only has an effect the next time the client binds to the socket, so make sure to call disconnect() if there was any prior communication.
Constructs a QCoapClient object for the given securityMode and sets parent as the parent object.
The default for securityMode is QtCoap::NoSecurity, which disables security.
[virtual noexcept]QCoapClient::~QCoapClient()
Destroys the QCoapClient object and frees up any resources. Note that QCoapReply objects that are returned from this class have the QCoapClient set as their parents, which means that they will be deleted along with it.
This signal is emitted whenever an error occurs. The reply parameter can be nullptr if the error is not related to a specific QCoapReply. The error parameter contains the error code.
This signal is emitted along with the QCoapReply::finished() signal whenever a CoAP reply is received, after either a success or an error. The reply parameter will contain a pointer to the reply that has just been received.
Sends a request to observe the target request and returns a new QCoapReply object which emits the QCoapReply::notified() signal whenever a new notification arrives.
Sends a request to observe the target url and returns a new QCoapReply object which emits the QCoapReply::notified() signal whenever a new notification arrives.
Sends the request using the POST method and returns a new QCoapReply object. Uses data as the payload for this request. If data is empty, the payload of the request will be used.
Sends the request using the POST method and returns a new QCoapReply object. Uses device content as the payload for this request. A null device is treated as empty content, in which case the payload of the request will be used.
Sends the request using the PUT method and returns a new QCoapReply object. Uses data as the payload for this request. If data is empty, the payload of the request will be used.
Sends the request using the PUT method and returns a new QCoapReply object. Uses device content as the payload for this request. A null device is treated as empty content, in which case the payload of the request will be used.
This signal is emitted when a unicast response to a multicast request arrives. The reply parameter contains a pointer to the reply that has just been received, message contains the payload and the message details, and sender contains the sender address.
Sets the ACK_RANDOM_FACTOR value defined in RFC 7252 - Section 4.2, to ackRandomFactor. This value should be greater than or equal to 1. The default is 1.5.
Sets the ACK_TIMEOUT value defined in RFC 7252 - Section 4.2 to ackTimeout in milliseconds. The default is 2000 ms.
This timeout only applies to confirmable messages. The actual timeout for reliable transmissions is a random value between ACK_TIMEOUT and ACK_TIMEOUT * ACK_RANDOM_FACTOR.
Sets the MAX_RETRANSMIT value defined in RFC 7252 - Section 4.2 to maximumRetransmitCount. This value should be less than or equal to 25. The default is 4.
Sets the MAX_SERVER_RESPONSE_DELAY value to responseDelay in milliseconds. The default is 250 seconds.
As defined in RFC 7390 - Section 2.5, MAX_SERVER_RESPONSE_DELAY is the expected maximum response delay over all servers that the client can send a multicast request to.
Sets the minimum token size to tokenSize in bytes. For security reasons it is recommended to use tokens with a length of at least 4 bytes. The default value for this parameter is 4 bytes.