async-std
async-std copied to clipboard
An Example for UDP Multicast
The code snippet here: https://docs.rs/async-std/1.1.0/async_std/net/struct.UdpSocket.html#method.join_multicast_v4 is a start, but as someone who has never used multicast before, I think a full example that does something like multicasting a given value every n seconds, while listening for packets from other multicasters could be very useful.
@matthewrobertbell I'd love to have this. Remember trying this back when runtime was new, and couldn't get it to work. Having a full example for this would be fantastic.
My understanding, however, is that in order for it to work locally (e.g. connect multiple clients) a flag needs to be set to enable ip re-use. This can currently only be done by running a syscall on the fd, or using https://docs.rs/socket2/0.3.11/socket2/ to initiate the socket with the right flags.
@matthewrobertbell if you'd like to give this a shot that'd be fantastic; I feel like this is a core thing a lot of applications might want to do, and having an example for this would be :100:
For what it's worth, rust-libp2p has an implementation of that (that uses async-std!), with the caveat that the content of the packets is spec'ed by libp2p. https://github.com/libp2p/rust-libp2p/blob/stable-futures/misc/mdns/src/service.rs
(the link is pointing to the stable-futures branch which we'll soon merge into master, so please look in master if the link is dead)
The API is unfortunately not perfect, and the docs are outdated, as we are in the middle of the refactoring and have to conform to traits that were designed around polling.
@tomaka thank you very much for the code, I think I have it working (including port reuse, running > 1 processes on the same port on my laptop).
@yoshuawuyts I intend to tidy up the code within my project, then extract it out as a basic example in the next few days.
@yoshuawuyts The code from rust-libp2p uses the net2 crate, but async-std does not. Would an example using net2 be an issue?
@matthewrobertbell async-std has From impls for std::net types; I believe it should be possible to go from net2 -> std -> async-std here. Definitely not opposed to it!
edit: it's also worth noting socket2 exists, which is more or less a successor to net2. I believe it's a bit less convenient to use though, but should be more flexible. Figured I'd mention it in case using this crate would be more straight forward.
@yoshuawuyts I intend to tidy up the code within my project, then extract it out as a basic example in the next few days.
Hi @matthewrobertbell , new user of async_std for UDP multicast here, did you manage to publish your example? That would help me so much 😄
Thank you !
I'm afraid I ended up switching the project to tokio, so I didn't get around to publishing the example.
On Tue, 8 Mar 2022 at 21:07, Pierrick @.***> wrote:
@yoshuawuyts https://github.com/yoshuawuyts I intend to tidy up the code within my project, then extract it out as a basic example in the next few days.
Hi @matthewrobertbell https://github.com/matthewrobertbell , new user of async_std for UDP multicast here, did you manage to publish your example? That would help me so much 😄
Thank you !
— Reply to this email directly, view it on GitHub https://github.com/async-rs/async-std/issues/592#issuecomment-1062209790, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAB3AKMUOPODTDUTVRPILN3U666STANCNFSM4JSINWOQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you were mentioned.Message ID: @.***>
-- Regards,
Matthew Bell
Thanks anyway. I will give a try to message-io which seems to use the same hint pointed by @yoshuawuyts :
use https://docs.rs/socket2/0.3.11/socket2/ to initiate the socket with the right flags.