Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should j5e include an http client/server module(s)? #53

Open
dtex opened this issue Jul 4, 2020 · 1 comment
Open

Should j5e include an http client/server module(s)? #53

dtex opened this issue Jul 4, 2020 · 1 comment

Comments

@dtex
Copy link
Owner

dtex commented Jul 4, 2020

The IOCP defines TCP Socket classes that can be used for this, and like the other classes, they are low level. When I've built things with J5 that interacted with the world over wifi I always found creating/writing the server to be more of a chore than controlling the hardware itself. Given that, does it make sense to include a barebones HTTP client/server module and possibly a simple router too?

It could be a minimal subset of the node.js HTTP or HTTP2 API.

Not sure this is even doable in a small enough module, but it sure would be nice to make this easier for people.

@phoddie
Copy link
Contributor

phoddie commented Jul 4, 2020

To be clear, i have no opinion on what j5e should incorporate. I do have some experience with network protocols on embedded devices, so i'm just responding to 'what is doable" with the hope that what I have to share may be helpful in your decision.

The Moddable SDK contains support for lots of network protocols, including;

  • DNS client
  • mDNS - both local name claiming and service advertising & discovery
  • HTTP client
  • HTTP server
  • WebSocket client
  • WebSocket server
  • SNTP client (and simple server)
  • Ping client
  • MQTT client
  • MQTT server (experimental)

Those are all written in JavaScript on top of the Moddable SDK's TCP and UDP sockets. (There are some small exceptions where a native function is used for performance, but that's a detail) The IO Class Pattern's TCP and UDP sockets are (more or less) functionally equivalent to the Moddable SDK. These all run on ESP8266 (and ESP32, Qualcomm QCA4020, macOS, Windows, and Linux).

It should be possible to re-host the Moddable SDK network protocol implementations on the IO Class Pattern version. That's something I hope to try, once I have a chance to update the ESP8266 implementation of the IO Class Pattern to match changes made to the specification over the last year.

The network protocol implementations in the Moddable SDK are minimal, to respect the resources of the device. They are more like protocol parsers and serializers than a friendly developer API. For an environment like j5e, they would feel bizarre. But, like you have done with the IO Class Pattern already, you could build up from there to support the protocols you wish with the API style you prefer.

Finally, the Moddable SDK also has a secure socket client (TLS). This may be used with the HTTP, MQTT, and WebSocket clients. It is a layer on top of the TCP socket and so should also be easily adapted to the IO Class Pattern implementation of TCP socket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants