go-coap icon indicating copy to clipboard operation
go-coap copied to clipboard

Responses to non-confirmable requests (RFC7252 section 5.2.3)

Open theisHafele opened this issue 1 year ago • 2 comments

From RFC7252 section 5.2.3

If the request message is Non-confirmable, then the response SHOULD be returned in a Non-confirmable message as well. However, an endpoint MUST be prepared to receive a Non-confirmable response (preceded or followed by an Empty Acknowledgement message) in reply to a Confirmable request, or a Confirmable response in reply to a Non-confirmable request.

Is this currently supported/handled by the library? If not, what's the idiomatic way of preparing the endpoint as a client using the go-coap library?

theisHafele avatar Oct 10 '24 12:10 theisHafele

Yes, it is supported. By default, it sends a confirmable response, but you can set the message type to Non/Con by using the function func (r *Message) SetType(typ message.Type). This type is also used throughout the entire blockwise transfer process.

jkralik avatar Oct 12 '24 17:10 jkralik

Thanks for the response. Sorry, I should have been more clear. I meant the part that says:

Confirmable response in reply to a Non-Confirmable request

So as a client sending a non-confirmable request, is a confirmable response handled or would I need to set up a server to handle it as a request?

theisHafele avatar Oct 18 '24 08:10 theisHafele

It's up to you to set the desired message type in the server handler. By default, if a non-confirmable request is received, the go-coap server sends a response with a confirmable message type, requiring the client to send an acknowledgment. However, you can use the SetType function to override this and have the server reply with a non-confirmable message as well.

jkralik avatar Oct 30 '24 21:10 jkralik