镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Support running as MDNS server (receiving multicast queries and responding) #3

Open

Description

@clue
No description provided.

Activity

  1. sharkydog commented on Oct 23, 2024

    @sharkydog

    This is actually not that hard to do.

    use React\Dns\Protocol\Parser as DnsParser;
    use React\Dns\Protocol\BinaryDumper as DnsEncoder;
    use React\Dns\Model\Message as DnsMessage;
    use React\Dns\Model\Record as DnsRecord;
    use Clue\React\Multicast\Factory as MulticastFactory;
    
    $receiver = (new MulticastFactory)->createReceiver('224.0.0.251:5353');
    
    $receiver->on('message', function($data, $addr) use($receiver) {
      try {
        $message = (new DnsParser)->parseMessage($data);
      } catch(\Exception $e) {
        return;
      }
    
      if($message->qr) {
        return;
      }
    
      foreach($message->questions as $query) {
        if($query->type != DnsMessage::TYPE_A) {
          continue;
        }
        if($query->name != 'test-shd.local') {
          continue;
        }
    
        $response = new DnsMessage;
        $response->qr = true;
    
        $response->answers[] = new DnsRecord(
          'test-shd.local', DnsMessage::TYPE_A,
          DnsMessage::CLASS_IN, 120,
          '192.168.1.123'
        );
    
        $response = (new DnsEncoder)->toBinary($response);
        //$receiver->send($response, $addr);
        $receiver->send($response, '224.0.0.251:5353');
        return;
      }
    });

    Now I can almost make my LAN services auto discover themselves.

  2. PaulRotmann commented on Aug 5, 2025

    @PaulRotmann
    Contributor

    @sharkydog This is a nice prototype that shows the basic concept working.

    However, there's still quite a bit of work needed to make this production-ready. The code makes assumptions about specific query names and would need a more flexible API design, comprehensive testing, and documentation to work reliably in different scenarios.

    This would require significant additional work to become a robust, general-purpose solution.

  3. sharkydog commented on Aug 5, 2025

    @sharkydog

    I already made a package, while not perfect, does the job for me.
    sharkydog/mdns

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needednew featureNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions