boazsegev / facil.io

Your high performance web application C framework
http://facil.io
MIT License
2.07k stars 136 forks source link

Support CoAP #41

Open beriberikix opened 5 years ago

beriberikix commented 5 years ago

CoAP is a protocol used in resource-constrained environments like IoT (see http://coap.technology.) libcoap is a popular C implementation of the protocol and includes a trivial server example. Could libcoap be used with facli.io?

boazsegev commented 5 years ago

Hi @beriberikix ,

Thanks for the question, I wasn't aware of CoAP until you posted this and I'm still reading through the links.

From an initial overview, I must admit that even though facil.io could support a CoAP application, it might not be the best fit.

CoAP assumes a stateless server, using UDP datagram messages rather than TCP/IP, while a lot of facil.io's library code is focused on managing stateful connections and managing tens of thousands of connections or more.

Also, CoAP assumes a constricted environment, sometimes with as little as 10Kb of memory space (possibly with no support for dynamic memory allocation). In contrast, when facil.io detects a failed memory allocation, it crashes, assuming an irrecoverable memory leak / error rather than a constricted environment.

Sure, there's a lot of code in facil.io that can be used for UDP connections or small footprint IoT communication, but it was designed for heavy loads.

If I had to design a working engine for CoAP, I'd probably use a lot of code from the facil.io core library... but I'm not sure facil.io is the best choice for light UDP loads, since it comes with extra baggage.

Kindly, Bo.