Skip to content

nanocoap, yacoap, and gcoap compared

Ken Bannister edited this page Oct 11, 2016 · 7 revisions

The table below shows the functions used by nanocoap, yacoap, and gcoap to handle requests and responses.

Incoming Request

nanocoap yacoap gcoap and Notes
coap_parse() coap_parse() gcoap uses the nanocoap coap_parse(), which differs from yacoap in the CoAP PDU struct and order of params.
coap_handle_req()
Callback provides a single coap_pkt_t for read and write.
coap_handle_request()
Callback provides separate pkts for read and write, and includes an array of resource structs.
nanocoap uses an internal array of 'endpoints', which are like resources. Both libraries assume that the server provides resources only for itself. There is no notion of an external application registering endpoints with the server.
gcoap allows an external application to register endpoints with gcoap_register_listener(). gcoap uses its own internal _handle_req(), which finds the callback from its list of registered arrays of endpoints.
Callback must set content type with coap_put_option_ct(), then writes the payload, and finally executes coap_build_reply(). coap_make_response() If a payload, callback executes gcoap_resp_init(), writes the payload, and then executes gcoap_finish(). If no payload, callback executes a single function, gcoap_response(). These functions accept a code for content type, which gcoap then uses to write the actual CoAP option.
N/A coap_build()
The server executes this function after the request callback.
N/A
sock_udp_send() sendto() gcoap calls its internal _send_buf().
All three functions require only buffer, length, and destination address/port.

Outgoing Request

nanocoap yacoap Notes and gcoap
Client executes coap_build_hdr(), and then coap_put_option_url(). Does not support a request payload yet. coap_make_request() If a payload, client executes gcoap_req_init()and writes the payload. If no payload, callback executes a single function, gcoap_response().
N/A
Since does not support request payload.
coap_build() gcoap_finish() if wrote a payload, otherwise N/A.
sock_udp_send() send_to() gcoap_req_send()
The send function for all three libraries requires buffer, length, and destination address/port. gcoap_req_send() also expects a handler callback for the response, and stores a memo of the request, including the callback, to match against the expected response.

Incoming Response

nanocoap yacoap Notes and gcoap
coap_parse() coap_parse() gcoap uses the nanocoap coap_parse().
N/A
Does not support generic response handling.
coap_handle_response()
Executes the callback set in coap_resource_t. Expects only a single outstanding request.
gcoap finds the memo for the request, with its internal _find_req_memo(). gcoap then executes the callback handler passed in to gcoap_req_send(). Supports a compile-time defined number of outstanding requests. Also supports a compile-time defined timeout for the response, and executes the same callback in this case.