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

UDP Support #1062

Closed
10 of 15 tasks
opichals opened this issue Feb 11, 2017 · 10 comments
Closed
10 of 15 tasks

UDP Support #1062

opichals opened this issue Feb 11, 2017 · 10 comments

Comments

@opichals
Copy link
Contributor

opichals commented Feb 11, 2017

UDP Support

The purpose of this ticket is to track Espruino native UDP support.
The intention is to loosely follow the node.js dgram (https://nodejs.org/api/dgram.html) module API .

The development is currently in progress and can be reviewed at master...opichals:espruino-udp

Phase 1

Minimal effort to get UDP working.

  • Introduce ST_UDP flag
  • Drop NetCreateFlags in favor of SocketType
  • Add SocketType argument to net->createsocket()
  • Implement ST_UDP handling (network_linux.c)
  • Validate feasibility for ESP8266 (network_esp8266.c)
  • Validate this being enough for JS mDNS implementation
  • Multicast support
  • Made 'on:message' the same as 'on:data' (node.js compat)
// server
let srv = dgram.createSocket('udp4');
srv.bind(41234, bsrv => {
  bsrv.on('message', function(msg, info) {
    // echo 1
    srv.send('echo1: '+msg, info.port, info.host);
    // echo 2 // TBD: using setTimeout() to separate the message packets
    setTimeout(() => srv.send('echo2: '+msg, info.port, info.host));
  });
});

// client
let sckt = dgram.createSocket('udp4');
sckt.on('message', function(msg, info) {
  console.log('c:message', msg, info.host, info.port);
});
sckt.send('Espruino UDP Message!', 41234, '127.0.0.1');

Issues

Messages greater than net->chunkSize seem to sometimes freeze the whole esp8266 board. This could be because of heap shortage (wasn't able to verify)

  • Drop messages bigger than net->chunkSize (536/2 - quite small, many osx Bonjour/mDNS messages are way bigger).

Cleanup

  • Working test_dgram_socket.js test
  • Fix cross-layer interfacing and avoid hacks
  • Add property name constants ("receiveData", "multicastGroup", ...) similarly to e.g. HTTP_NAME_RECEIVE_DATA
  • Add doc comments to the added function parameters in network.h/c files

Phase 2

Separating send message packets (separate pull request).

  • Combine the socketserver:receiveInfo/receiveData, create a message data object {data, host, port} and pass to clientRequestWrite
  • Adapt to make it send every send() call separately, not concatenating to a stream (pushData)
// server
let srv = dgram.createSocket('udp4');
srv.bind(41234, bsrv => {
  bsrv.on('message', function(msg, info) {
    // echo 1
    bsrv.send('echo1: '+msg, info.port, info.host);
    // echo 2 (separate message/packet)
    bsrv.send('echo2: '+msg, info.port, info.host);
  });
});
@wilberforce
Copy link
Member

@opichals

I'm interested in following as we'll need to bring the code into the esp32 branch. The esp32 network code is cloned off the Linux base, so what every is working for Linux code be ported...

@opichals
Copy link
Contributor Author

I assume the ESP32 related changes are way more complex so I would wait for it to be merged to master and I will rebase on top. What do you think?

@wilberforce
Copy link
Member

@opichals
Actually the esp32 network code is very similar to the Linux network code, so it should be a simple update.

@opichals
Copy link
Contributor Author

For UDP there are updates to the JsNetwork interface which applies and have to be adjusted/synced for all boards netowrk stacks. My hunch is to leave this and add UDP support after the ESP32 stuff is merged.

@hungryforcodes
Copy link

Was there any updates on this by the way? I'm curious about some of the new things this might offer, including mDNS.

@opichals
Copy link
Contributor Author

@hungryforcodes I am struggling to understand the Espruino's networking stack in detail as the changes affect all boards. Unfortunately I wasn't able to work on this recently.

On the positive side I got it working with some limitations including a basic mDNS.js responder (Linux, ESP8266 so far). The mDNS support could prove to be quite limited though due to the small amount of RAM available.

@wilberforce
Copy link
Member

The esp32 branch has been merged into mainstream, and the network code was cloned from Linux so should be easy to merge. There is more memory on this board so you would not have the same memory limitations as the esp8266

@hungryforcodes
Copy link

@opichals Thanks for the update :)

@wilberforce Yes we understand your position on the ESP32 :)

@gfwilliams
Copy link
Member

I think this is probably closable now?

@opichals
Copy link
Contributor Author

Sounds all right, I have my minor TODOs elsewhere.

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

4 participants