Closed emmanuelay closed 1 year ago
Maybe @jkralik knows more about this? :-)
@emmanuelay
- How do I access the message ID that the client sent to the server from within the handler above? The reason is that I want to store the message ID and perform an eventual ACK at a later stage.
When you create server you need to use option udp.WithHandlerFunc
instead of udp.WithMux
. At the handler you get msg *pool.Message
which has functions msg.MessageID()
https://github.com/plgd-dev/go-coap/blob/4d466801917705aec7cd97b6b53c7502d4c1f7c5/udp/message/pool/message.go#L52
- If the client has sent a confirmable message to the server, and I wish to confirm it later in a completely separate process. Does the server automatically send ACKs which is implied in the documentation? And if so, is there any way to prevent the package from sending an ACK automatically?
Yes it is send automatically. It sends ack in separated message/response of request. For your usecase just don't send the response immediately and ACK will be send via separate message. And then you can create response later after you process request similar as: https://github.com/plgd-dev/go-coap/blob/4d466801917705aec7cd97b6b53c7502d4c1f7c5/examples/observe/server/main.go#L78
Would be useful to be able to access the MessageID somehow in logging middlewares using udp.WithMux
. Logging the message id helps debugging client issues, for example. Right now I'm using a logging CoAP proxy for this.
Would be useful to be able to access the MessageID somehow in logging middlewares using
udp.WithMux
. Logging the message id helps debugging client issues, for example. Right now I'm using a logging CoAP proxy for this.
@JosefWN with blockwise, mux gets completed constructed message, so it is not possible at the layer mux. In go-coap/v3
you can read all MessageID via https://github.com/plgd-dev/go-coap/blob/b8901963ae43acd9a14f98b3d47ec17b26b38e7a/options/commonOptions.go#L278
Feel free to reopen it but v3 allows you to set MessageId
and also Type
.
I am writing a CoAP server which accepts requests using UDP. My code utilizes handlers and the signature looks like this:
I have two questions that I would really appreciate if you could help me out with:
1) How do I access the message ID that the client sent to the server from within the handler above? The reason is that I want to store the message ID and perform an eventual ACK at a later stage.
2) If the client has sent a confirmable message to the server, and I wish to confirm it later in a completely separate process. Does the server automatically send ACKs which is implied in the documentation? And if so, is there any way to prevent the package from sending an ACK automatically?