PySide6.QtCoap.QCoapClient¶
- class QCoapClient¶
The
QCoapClientclass allows the application to send CoAP requests and receive replies.Details
The
QCoapClientclass contains signals that get triggered when the reply of a sent request has arrived.The application can use a
QCoapClientto send requests over a CoAP network. It provides functions for standard requests: each returns aQCoapReplyobject, to which the response data shall be delivered; this can be read when thefinished()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")));
Note
After processing of the request has finished, it is the responsibility of the user to delete the
QCoapReplyobject at an appropriate time. Do not directly delete it inside the slot connected tofinished(). You can use the deleteLater() function.You can also use an observe request. This can be used as above, or more conveniently with the
notified()signal: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:
client->cancelObserve(reply);
When a reply arrives, the
QCoapClientemits afinished()signal.Note
For a discovery request, the returned object is a
QCoapResourceDiscoveryReply. It can be used the same way as aQCoapReplybut contains also a list of resources.Synopsis¶
Methods¶
def
__init__()def
cancelObserve()def
deleteResource()def
disconnect()def
discover()def
get()def
observe()def
post()def
put()def
setAckTimeout()def
setBlockSize()
Signals¶
def
error()def
finished()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
- __init__([securityMode=QtCoap.SecurityMode.NoSecurity[, parent=None]])¶
- Parameters:
securityMode –
SecurityModeparent –
QObject
Constructs a
QCoapClientobject for the givensecurityModeand setsparentas the parent object.The default for
securityModeisNoSecurity, which disables security.- cancelObserve(notifiedReply)¶
- Parameters:
notifiedReply –
QCoapReply
Cancels the observation of a resource using the reply
notifiedReplyreturned by theobserve()method.See also
- cancelObserve(url)
- Parameters:
url –
QUrl
Cancels the observation of a resource identified by the
url.See also
- deleteResource(request)¶
- Parameters:
request –
QCoapRequest- Return type:
Sends the
requestusing the DELETE method and returns a newQCoapReplyobject.See also
- deleteResource(url)
- Parameters:
url –
QUrl- Return type:
Sends a DELETE request to the target
url.See also
- disconnect()¶
Closes the open sockets and connections to free the transport.
Note
In the secure mode this needs to be called before changing the security configuration or connecting to another server.
See also
- discover(baseUrl[, discoveryPath=QLatin1String("/.well-known/core")])¶
- Parameters:
baseUrl –
QUrldiscoveryPath – str
- Return type:
Discovers the resources available at the given
urland returns a newQCoapResourceDiscoveryReplyobject which emits thediscovered()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 RFC 6690 .See also
- discover([group=QtCoap.MulticastGroup.AllCoapNodesIPv4[, port=QtCoap.DefaultPort[, discoveryPath=QLatin1String("/.well-known/core")]]])
- Parameters:
group –
MulticastGroupport – int
discoveryPath – str
- Return type:
Discovers the resources available at the endpoints which have joined the
groupat the givenport. Returns a newQCoapResourceDiscoveryReplyobject which emits thediscovered()signal whenever a response arrives. Thegroupis one of the CoAP multicast group addresses and defaults toAllCoapNodesIPv4.Discovery path defaults to “/.well-known/core”, but can be changed by passing a different path to
discoveryPath. Discovery is described in RFC 6690 .See also
- error(reply, error)¶
- Parameters:
reply –
QCoapReplyerror –
Error
This signal is emitted whenever an error occurs. The
replyparameter can beNoneif the error is not related to a specificQCoapReply. Theerrorparameter contains the error code.See also
- finished(reply)¶
- Parameters:
reply –
QCoapReply
This signal is emitted along with the
finished()signal whenever a CoAP reply is received, after either a success or an error. Thereplyparameter will contain a pointer to the reply that has just been received.See also
- get(request)¶
- Parameters:
request –
QCoapRequest- Return type:
Sends the
requestusing the GET method and returns a newQCoapReplyobject.See also
- get(url)
- Parameters:
url –
QUrl- Return type:
Sends a GET request to
urland returns a newQCoapReplyobject.See also
- observe(request)¶
- Parameters:
request –
QCoapRequest- Return type:
Sends a request to observe the target
requestand returns a newQCoapReplyobject which emits thenotified()signal whenever a new notification arrives.- observe(request)
- Parameters:
request –
QUrl- Return type:
Sends a request to observe the target
urland returns a newQCoapReplyobject which emits thenotified()signal whenever a new notification arrives.- post(request, device)¶
- Parameters:
request –
QCoapRequestdevice –
QIODevice
- Return type:
Sends the
requestusing the POST method and returns a newQCoapReplyobject. Usesdevicecontent as the payload for this request. A null device is treated as empty content.Note
The device has to be open and readable before calling this function.
See also
- post(request[, data=QByteArray()])
- Parameters:
request –
QCoapRequestdata –
QByteArray
- Return type:
Sends the
requestusing the POST method and returns a newQCoapReplyobject. Usesdataas the payload for this request. Ifdatais empty, the payload of therequestwill be used.See also
- post(url[, data=QByteArray()])
- Parameters:
url –
QUrldata –
QByteArray
- Return type:
Sends a POST request to
urland returns a newQCoapReplyobject. Usesdataas the payload for this request.See also
- put(request, device)¶
- Parameters:
request –
QCoapRequestdevice –
QIODevice
- Return type:
Sends the
requestusing the PUT method and returns a newQCoapReplyobject. Usesdevicecontent as the payload for this request. A null device is treated as empty content, in which case the payload of therequestwill be used.Note
The device has to be open and readable before calling this function.
See also
- put(request[, data=QByteArray()])
- Parameters:
request –
QCoapRequestdata –
QByteArray
- Return type:
Sends the
requestusing the PUT method and returns a newQCoapReplyobject. Usesdataas the payload for this request. Ifdatais empty, the payload of therequestwill be used.See also
- put(url[, data=QByteArray()])
- Parameters:
url –
QUrldata –
QByteArray
- Return type:
Sends a PUT request to
urland returns a newQCoapReplyobject. Usesdataas the payload for this request.See also
- responseToMulticastReceived(reply, message, sender)¶
- Parameters:
reply –
QCoapReplymessage –
QCoapMessagesender –
QHostAddress
This signal is emitted when a unicast response to a multicast request arrives. The
replyparameter contains a pointer to the reply that has just been received,messagecontains the payload and the message details, andsendercontains the sender address.See also
- setAckRandomFactor(ackRandomFactor)¶
- Parameters:
ackRandomFactor – float
Sets the
ACK_RANDOM_FACTORvalue defined in RFC 7252 - Section 4.2 , toackRandomFactor. This value should be greater than or equal to 1. The default is 1.5.See also
- setAckTimeout(ackTimeout)¶
- Parameters:
ackTimeout – int
Sets the
ACK_TIMEOUTvalue defined in RFC 7252 - Section 4.2 toackTimeoutin 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_TIMEOUTandACK_TIMEOUT * ACK_RANDOM_FACTOR.See also
- setBlockSize(blockSize)¶
- Parameters:
blockSize – int
Sets the maximum block size used by the protocol to
blockSizewhen sending requests and receiving replies. The block size must be a power of two.- setMaximumRetransmitCount(maximumRetransmitCount)¶
- Parameters:
maximumRetransmitCount – int
Sets the
MAX_RETRANSMITvalue defined in RFC 7252 - Section 4.2 tomaximumRetransmitCount. This value should be less than or equal to 25. The default is 4.- setMaximumServerResponseDelay(responseDelay)¶
- Parameters:
responseDelay – int
Sets the
MAX_SERVER_RESPONSE_DELAYvalue toresponseDelayin milliseconds. The default is 250 seconds.As defined in RFC 7390 - Section 2.5 ,
MAX_SERVER_RESPONSE_DELAYis the expected maximum response delay over all servers that the client can send a multicast request to.- setMinimumTokenSize(tokenSize)¶
- Parameters:
tokenSize – int
Sets the minimum token size to
tokenSizein 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.- setSecurityConfiguration(configuration)¶
- Parameters:
configuration –
QCoapSecurityConfiguration
Sets the security configuration parameters from
configuration. Configuration will be ignored if theNoSecuritymode is used.Note
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
- setSocketOption(option, value)¶
- Parameters:
option –
SocketOptionvalue – object
Sets the QUdpSocket socket
optiontovalue.