udp/client: pools, messages and conversion
daenney opened this issue · comments
I'm trying to rewrite something that was written with the old/pre-v1 go-coap implementation, but I'm struggling a bit with all the different message types, pools and how to use them.
My case is pretty simple, I just have a client that needs to Get and Post a few things and then does an Observe
. In doing so I ended up with something basic like:
cl, _ := udp.Dial(...)
cl.Post(...)
The problem I'm running into is with Observe
. The messages I get back from there are confirmable, and I have to confirm them otherwise after a while the server assumes the client is dead and stops sending data.
So you get something like
if msg.Type() == udpmsg.Confirmable {
// do something
}
The problem I'm running into is that I'd like to use the pool.Message
here to build up the message, because it has many useful functions like the different SetXXX
ers, instead of having to do this myself in udp/pool.Message
by constantly allocation and growing the buffer to store the Options
in etc.
However, there doesn't seem to be a way that I can convert from pool.Message
to the equivalent udp/pool.Message
, which is what WriteMessage()
on the udp,ClientConn
returned by udp.Dial
expects. udp/ClientConn.Client
expects a message.Message
and though I can go from udp/pool.Message
to message.Message
using udp/pool.ConvertTo
, I can't seem to go from pool.Message
to message.Message.
I sort of feel like I'm missing something here? It feels like there should be a way to use a convenient facility like pool.Message
to build up a message and then pass that on somehow to the udp/tcp/dtls ClientConn or Client, but I can't put the pieces together.
Do I have to use udp/pool.Message
and build up everything myself?
This was unified at v3
there is one pool
package and one message
package over tcp/dtls/udp packages. It is simpler to use it.