IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QCoapClient Class

The https:// class allows the application to send CoAP requests and receive replies.

All functions in this class are https://.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QCoapClient Class▲

  • Header: QCoapClient

  • qmake: QT += coap

  • Inherits: https://

Detailed Description▲

The https:// class contains signals that get triggered when the reply of a sent request has arrived.

The application can use a https:// to send requests over a CoAP network. It provides functions for standard requests: each returns a https:// object, to which the response data shall be delivered; this can be read when the https://() signal arrives.

A simple request can be sent with:

 
Sélectionnez
QCoapClient *client = new QCoapClient(this);
connect(client, &QCoapClient::finished, this, &TestClass::slotFinished);
client->get(QCoapRequest(Qurl("coap://coap.me/test")));

After processing of the request has finished, it is the responsibility of the user to delete the https:// object at an appropriate time. Do not directly delete it inside the slot connected to https://(). You can use the https://() function.

You can also use an observe request. This can be used as above, or more conveniently with the QCoapReply::notified() signal:

 
Sélectionnez
QCoapRequest request = QCoapRequest(Qurl("coap://coap.me/obs"));
QCoapReply *reply = client->observe(request);
connect(reply, &QCoapReply::notified, this, &TestClass::slotNotified);

And the observation can be cancelled with:

 
Sélectionnez
client->cancelObserve(reply);

When a reply arrives, the https:// emits a https://() signal.

For a discovery request, the returned object is a https://. It can be used the same way as a https:// but contains also a list of resources.

See Also▲

See also https://, https://, https://

Member Function Documentation▲

 

[explicit] QCoapClient::QCoapClient(QtCoap::SecurityMode securityMode = QtCoap::SecurityMode::NoSecurity, QObject *parent = nullptr)▲

Constructs a https:// object for the given securityMode and sets parent as the parent object.

The default for securityMode is https://, which disables security.

This connects using a QCoapQUdpConnection; to use a custom transport, sub-class QCoapConnection and pass an instance to one of the other constructors.

[virtual] QCoapClient::~QCoapClient()▲

Destroys the https:// object and frees up any resources. Note that https:// objects that are returned from this class have the https:// set as their parents, which means that they will be deleted along with it.

void QCoapClient::cancelObserve(QCoapReply *notifiedReply)▲

This is an overloaded function.

Cancels the observation of a resource using the reply notifiedReply returned by the https://() method.

See Also▲

See also https://()

void QCoapClient::cancelObserve(const QUrl &url)▲

This is an overloaded function.

Cancels the observation of a resource identified by the url.

See Also▲

See also https://()

QCoapReply *QCoapClient::deleteResource(const QCoapRequest &request)▲

Sends the request using the DELETE method and returns a new https:// object.

See Also▲

See also https://(), https://(), https://(), https://(), https://()

QCoapReply *QCoapClient::deleteResource(const QUrl &url)▲

This is an overloaded function.

Sends a DELETE request to the target url.

See Also▲

See also https://(), https://(), https://(), https://(), https://()

void QCoapClient::disconnect()▲

Closes the open sockets and connections to free the transport.

In the secure mode this needs to be called before changing the security configuration or connecting to another server.

See Also▲

See also https://()

QCoapResourceDiscoveryReply *QCoapClient::discover(const QUrl &url, const QString &discoveryPath = QLatin1String("/.well-known/core"))▲

Discovers the resources available at the given url and returns a new https:// object which emits the QCoapResourceDiscoveryReply::discovered() signal whenever the response arrives.

Discovery path defaults to "/.well-known/core", but can be changed by passing a different path to discoveryPath. Discovery is described in https://.

See Also▲

See also https://(), https://(), https://(), https://(), https://()

QCoapResourceDiscoveryReply *QCoapClient::discover(QtCoap::MulticastGroup group = QtCoap::MulticastGroup::AllCoapNodesIPv4, int port = QtCoap::DefaultPort, const QString &discoveryPath = QLatin1String("/.well-known/core"))▲

This is an overloaded function.

Discovers the resources available at the endpoints which have joined the group at the given port. Returns a new https:// object which emits the QCoapResourceDiscoveryReply::discovered() signal whenever a response arrives. The group is one of the CoAP multicast group addresses and defaults to https://.

Discovery path defaults to "/.well-known/core", but can be changed by passing a different path to discoveryPath. Discovery is described in https://.

See Also▲

See also https://(), https://(), https://(), https://(), https://()

void QCoapClient::error(QCoapReply *reply, QtCoap::Error error)▲

This signal is emitted whenever an error occurs. The reply parameter can be nullptr if the error is not related to a specific https://. The error parameter contains the error code.

See Also▲

See also https://(), QCoapReply::error(), https://()

void QCoapClient::finished(QCoapReply *reply)▲

This signal is emitted along with the https://() 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.

See Also▲

See also https://(), https://(), QCoapReply::error()

QCoapReply *QCoapClient::get(const QCoapRequest &request)▲

Sends the request using the GET method and returns a new https:// object.

See Also▲

See also https://(), https://(), https://(), https://(), https://()

QCoapReply *QCoapClient::get(const QUrl &url)▲

This is an overloaded function.

Sends a GET request to url and returns a new https:// object.

See Also▲

See also https://(), https://(), https://(), https://(), https://()

QCoapReply *QCoapClient::observe(const QCoapRequest &request)▲

Sends a request to observe the target request and returns a new https:// object which emits the QCoapReply::notified() signal whenever a new notification arrives.

See Also▲

See also https://(), https://(), https://(), https://(), https://(), https://()

QCoapReply *QCoapClient::observe(const QUrl &url)▲

This is an overloaded function.

Sends a request to observe the target url and returns a new https:// object which emits the QCoapReply::notified() signal whenever a new notification arrives.

See Also▲

See also https://(), https://(), https://(), https://(), https://(), https://()

QCoapReply *QCoapClient::post(const QCoapRequest &request, const QByteArray &data = QByteArray())▲

Sends the request using the POST method and returns a new https:// object. Uses data as the payload for this request. If data is empty, the payload of the request will be used.

See Also▲

See also https://(), https://(), https://(), https://(), https://()

QCoapReply *QCoapClient::post(const QCoapRequest &request, QIODevice *device)▲

This is an overloaded function.

Sends the request using the POST method and returns a new https:// object. Uses device content as the payload for this request. A null device is treated as empty content.

The device has to be open and readable before calling this function.

See Also▲

See also https://(), https://(), https://(), https://(), https://()

QCoapReply *QCoapClient::post(const QUrl &url, const QByteArray &data = QByteArray())▲

This is an overloaded function.

Sends a POST request to url and returns a new https:// object. Uses data as the payload for this request.

See Also▲

See also https://(), https://(), https://(), https://(), https://()

QCoapReply *QCoapClient::put(const QCoapRequest &request, const QByteArray &data = QByteArray())▲

Sends the request using the PUT method and returns a new https:// object. Uses data as the payload for this request. If data is empty, the payload of the request will be used.

See Also▲

See also https://(), https://(), https://(), https://(), https://()

QCoapReply *QCoapClient::put(const QCoapRequest &request, QIODevice *device)▲

This is an overloaded function.

Sends the request using the PUT method and returns a new https:// object. Uses device content as the payload for this request. A null device is treated as empty content.

The device has to be open and readable before calling this function.

See Also▲

See also https://(), https://(), https://(), https://(), https://()

QCoapReply *QCoapClient::put(const QUrl &url, const QByteArray &data = QByteArray())▲

This is an overloaded function.

Sends a PUT request to url and returns a new https:// object. Uses data as the payload for this request.

See Also▲

See also https://(), https://(), https://(), https://(), https://()

void QCoapClient::responseToMulticastReceived(QCoapReply *reply, const QCoapMessage &message, const QHostAddress &sender)▲

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.

See Also▲

See also https://(), https://(), QCoapReply::error()

void QCoapClient::setAckRandomFactor(double ackRandomFactor)▲

Sets the ACK_RANDOM_FACTOR value defined in https://, to ackRandomFactor. This value should be greater than or equal to 1. The default is 1.5.

See Also▲

See also https://()

void QCoapClient::setAckTimeout(uint ackTimeout)▲

Sets the ACK_TIMEOUT value defined in https:// 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.

See Also▲

See also https://()

void QCoapClient::setBlockSize(quint16 blockSize)▲

Sets the maximum block size used by the protocol to blockSize when sending requests and receiving replies. The block size must be a power of two.

void QCoapClient::setMaximumRetransmitCount(uint maximumRetransmitCount)▲

Sets the MAX_RETRANSMIT value defined in https:// to maximumRetransmitCount. This value should be less than or equal to 25. The default is 4.

void QCoapClient::setMaximumServerResponseDelay(uint responseDelay)▲

Sets the MAX_SERVER_RESPONSE_DELAY value to responseDelay in milliseconds. The default is 250 seconds.

As defined in https://, MAX_SERVER_RESPONSE_DELAY is the expected maximum response delay over all servers that the client can send a multicast request to.

void QCoapClient::setMinimumTokenSize(int tokenSize)▲

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.

void QCoapClient::setSecurityConfiguration(const QCoapSecurityConfiguration &configuration)▲

Sets the security configuration parameters from configuration. Configuration will be ignored if the https:// mode is used.

This method must be called before the handshake starts. If you need to change the security configuration after establishing a secure connection with the server, the client needs to be disconnected first.

See Also▲

See also https://()

void QCoapClient::setSocketOption(QAbstractSocket::SocketOption option, const QVariant &value)▲

Sets the https:// socket option to value.

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+   

Ce document est disponible sous la licence https:// telle que publiée par la Free Software Foundation.