• CoapReply
  • CoapReply Class

    Represents a reply of a CoAP request. More...

    Header: #include <CoapReply>
    Inherits:

    Public Types

    enum Error { NoError, HostNotFoundError, TimeoutError, InvalidUrlSchemeError, InvalidPduError }

    Public Functions

    CoapPdu::ContentType contentType() const
    Error error() const
    QString errorString() const
    bool isFinished() const
    bool isRunning() const
    CoapPdu::MessageType messageType() const
    QByteArray payload() const
    CoapRequest request() const
    CoapPdu::StatusCode statusCode() const

    Signals

    void error(const Error & code)
    void finished()
    void timeout()

    Detailed Description

    Represents a reply of a CoAP request.

    The CoapReply class contains the data and headers for a request sent with Coap client.

    Note: Please don't forget to delete the reply once it is finished.

    Example

    Coap *coap = new Coap(this);
    connect(coap, SIGNAL(replyFinished(CoapReply*)), this, SLOT(onReplyFinished(CoapReply*)));
    
    CoapRequest request(QUrl("coap://example.com/"));
    
    CoapReply *reply = coap->ping(request);
    void MyClass::onReplyFinished(CoapReply *reply)
    {
        if (reply->error() != CoapReply::NoError) {
          qWarning() << "Reply finished with error" << reply->errorString();
          reply->deleteLater();
          return;
        }
    
        qDebug() << "Reply finished" << reply;
        reply->deleteLater();
    }

    See also Coap and CoapRequest.

    Member Type Documentation

    enum CoapReply::Error

    ConstantValueDescription
    CoapReply::NoError0No error occurred. Everything ok.
    CoapReply::HostNotFoundError1The remote host name was not found (invalid hostname).
    CoapReply::TimeoutError2The server did not respond after 4 retransmissions.
    CoapReply::InvalidUrlSchemeError3The given URL does not have a valid scheme.
    CoapReply::InvalidPduError4The package data unit (PDU) could not be parsed successfully.

    Member Function Documentation

    CoapPdu::ContentType CoapReply::contentType() const

    Returns the CoapPdu::ContentType of this CoapReply.

    Error CoapReply::error() const

    Returns error CoapReply::Error of the CoapReply.

    See also errorString().

    [signal] void CoapReply::error(const Error & code)

    This signal is emitted when an error occurred. The given code represents the CoapReply::Error.

    See also error() and errorString().

    QString CoapReply::errorString() const

    Returns error string of the CoapReply.

    See also error().

    [signal] void CoapReply::finished()

    This signal is emitted when the reply is finished.

    bool CoapReply::isFinished() const

    Returns true if the CoapReply is finished.

    See also finished().

    bool CoapReply::isRunning() const

    Returns true if the CoapReply is running.

    See also finished().

    CoapPdu::MessageType CoapReply::messageType() const

    Returns the CoapPdu::MessageType of this CoapReply.

    QByteArray CoapReply::payload() const

    Returns the payload of this CoapReply. The payload will be available once the CoapReply is finished.

    See also isFinished.

    CoapRequest CoapReply::request() const

    Returns the request for this CoapReply.

    CoapPdu::StatusCode CoapReply::statusCode() const

    Returns the CoapPdu::StatusCode of this CoapReply.

    [signal] void CoapReply::timeout()

    This signal is emitted when the reply took to long.