[Libwebsockets] 回复: 回复: [Question] Does libwebsockets support sending and receiving multicast packets?
tanxiaojun at oppo.com
Wed Jun 24 08:21:07 CEST 2020
Sorry, I misunderstood before. I’m just starting to use it now.
If there is progress in the future, I would be happy to share it.
发件人: Andy Green <andy at warmcat.com>
发送时间: 2020年6月24日 12:42
收件人: 谭小俊(Xiaojun Tan) <tanxiaojun at oppo.com>; libwebsockets at ml.libwebsockets.org
抄送: 胡岳伟(Wei) <huyuewei at oppo.com>; 高宇(kevin) <gaoyu at oppo.com>
主题: Re: 回复: [Libwebsockets] [Question] Does libwebsockets support sending and receiving multicast packets?
On 6/24/20 4:42 AM, 谭小俊(Xiaojun Tan) wrote:
> Hi, Andy,
> Thank you for your reply. Thanks a lot.
> Where can I get the patch(the generic lws mDNS client / server patch) you mentioned.
"out of tree" means it's not pushed as part of lws yet even on master, since it's incomplete, it's one of many half-done things on my stgit stack.
But it's able to receive mDNS group broadcasts inside lws semantics, and IIRC emit a canned group broadcast.
$ sudo ./bin/lws-api-test-mdns -i wlo1
[2020/06/24 05:22:50:6001] U: LWS API selftest: MDNS
[2020/06/24 05:22:50:6196] U: main: requesting MDNS for wlo1
[2020/06/24 05:22:50:6197] N: lws_mdns_retry_conn: created wsi_raw:
0x1edc980 on wlo1
[2020/06/24 05:22:50:6199] N:
[2020/06/24 05:22:50:6199] N: 0000: 00 00 00 00 00 01 00 00 00 00 00 00
09 5F 73 65 ............._se
[2020/06/24 05:22:50:6199] N: 0010: 72 76 69 63 65 73 07 5F 64 6E 73 2D
73 64 04 5F rvices._dns-sd._
[2020/06/24 05:22:50:6199] N: 0020: 75 64 70 05 6C 6F 63 61 6C 00 00 0C
00 01 udp.local.....
At that point, I realized the next step was probably integrate with the lws Async DNS parser
...since I didn't really appreciate until I saw the packets that mDNS really means literally DNS protocol inside... ultimately things probably want to consume this by being able to resolve "xyz.local" using same apis as external name resolution automagically.
They will also want to be able to emit canned announcements and discover what's around on the subnet... this could be done by reusing the async dns local cache arrangements or something else... either way it has to have some kind of lru limit or compression scheme otherwise tiny targets like ESP32 will OOM on busy subnets.
And I noticed mDNS broadcast collection / discovery / LRU management is quite similar to WLAN scan handling. I intend to write a generic wrapper for that too, maybe that should also cover mDNS results management.
If you're willing to cooperate to complete enough of it to be useful and add it to lws, I'll be happy to push it somewhere so we can do that.
> 发件人: andy at warmcat.com <andy at warmcat.com>
> 发送时间: 2020年6月24日 11:33
> 收件人: libwebsockets at ml.libwebsockets.org; 谭小俊(Xiaojun Tan)
> <tanxiaojun at oppo.com>; libwebsockets at ml.libwebsockets.org
> 抄送: 胡岳伟(Wei) <huyuewei at oppo.com>
> 主题: Re: [Libwebsockets] [Question] Does libwebsockets support sending and receiving multicast packets?
> On June 24, 2020 3:04:40 AM UTC, "谭小俊(Xiaojun Tan)" <tanxiaojun at oppo.com> wrote:
>> Hi, all,
>> Sorry to bother you.
>> I recently started using libwebsockets for sending and receiving
>> network packets.
>> But when I plan to use it to send and receive UDP multicast packets,
>> I don't know how to do it. I also did not find corresponding tips
>> from any documents and examples.
>> And there is no corresponding code in the source code, so I want to
>> ask whether it supports sending and receiving multicast packets. If
>> not, can I manually join the multicast group through the
>> corresponding sockfd in libwebsockets (using setsockopt).
> Multicast groups is a long way away from lws original focus only on tcp based protocols. But lws is slowly spreading out there, eg, it comes with dhcp client, ntp client and async dns resolver now all of which are UDP.
> I didn't get a chance to complete it yet but there is also a generic lws mDNS client / server patch out of tree that is of course multicast... afaik mDNS is the only common use for multicasting. There, it wraps the multicasting C apis in mDNS semantics and exposes only mDNS apis. The mDNS implementation is part of lws rather than user code but unless there's another use for multicast I didn't think about, the general plan is eventually provide mDNS rather than provide wrappers for standard multicast apis. As you say you can just use the standard C multicast apis on the socketfd.
>> This e-mail and its attachments contain confidential information from
>> OPPO, which is intended only for the person or entity whose address
>> is listed above. Any use of the information contained herein in any
>> way (including, but not limited to, total or partial disclosure,
>> reproduction, or dissemination) by persons other than the intended
>> recipient(s) is prohibited. If you receive this e-mail in error,
>> please notify the sender by phone or email immediately and delete it!
More information about the Libwebsockets