This article is a mirror article of machine translation, please click here to jump to the original article.

View: 46794|Reply: 2

[Source] .NET Core is based on mDNS service discovery and registration

[Copy link]
Posted on 8/25/2021 6:36:42 PM | | | |
mDNS is Multicast DNS, which mainly enables hosts in the LAN to discover and communicate with each other without a traditional DNS server, and the port used is5353, follow the DNS protocol, and use the existing DNS information structure, syntax, and resource record types. And no new action code or response code is specified. In the LAN, the device and the device need to know each other's IP address before communicating with each other, in most cases, the IP of the device is not a static IP address, but a dynamically assigned IP address through the DHCP protocol, how to discover the device, is to show its skills by MDNS, for example: now the communication between the Internet of Things device and the app, either the app through broadcasting, or through multicast, send some specific information, the interested device responds, to achieve the discovery of LAN devices, of course, mDNS is more powerful than this.

Consul HTTP API interface call
https://www.itsvse.com/thread-9578-1-1.html

【Architecture】ASP.NET Core is highly available based on Consul services
https://www.itsvse.com/thread-9422-1-1.html

Architecture: ASP.NET Core dynamically configures hot updates based on Consul
https://www.itsvse.com/thread-9421-1-1.html

[Architecture]. net/c# implements distributed configuration of Key/Value store based on Consul
https://www.itsvse.com/thread-9420-1-1.html

Windows builds a standalone version of Nacos 2.0.3
https://www.itsvse.com/thread-10040-1-1.html


Service registration

First, create a new .NET Core 3.1 project and use the nuget command to reference the following package:


The current service name and address are discovered by broadcasting, with the following code:



Service Discovery

Service discovery, which we can achieve through .NET/C# code, is as follows:

You can also enable service discovery to receive all broadcasts, the code is as follows:



Server: CentOS Linux release 7.8.2003 (Core), by installing avahi and avahi-tools tools, the service can also be discovered, the installation command is as follows:

avahi-daemon is a service daemon that runs on a Linux operating system and implements a lookup for a network-based Zeroconf service on a client machine. This service can implement DNS service discovery and DNS multicast specifications for the Zeroconf network. The user program receives notifications of discovered network services and resources through Linux D-Bus messaging. This daemon works with caching user program replies to help reduce network traffic resulting from replies.
Run the avahi-daemon.service service with the following command:



You can use the avahi-browse command after installing avahi-tools.

You can view all MDNS services in the LAN with the following command:

To query a specified service, the command is as follows:




If you close the .NET Core application and query the service on another server, the following error will be reported:

+   eth0 IPv4 test                                          _itsvse_discovery._tcp local
Failed to resolve service 'test' of type '_itsvse_discovery._tcp' in domain 'local': Timeout reached


Attached is the source code:

Tourists, if you want to see the hidden content of this post, pleaseReply


(End)





Previous:zookeeper startup failed No snapshot found, but there are log entries ...
Next:nginx access issue connect() to 127.0.0.1:8080 failed (13: Permission den...
Posted on 8/26/2021 3:19:56 PM |

Pass by and take a look, thank you for sharing
 Landlord| Posted on 10/17/2021 3:40:33 PM |
If centos 8 can't find avahi-tools and can't install, try the following command:

Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com