简体   繁体   English

使用C#进行MDNS服务注册

[英]MDNS Service Registration using C#

I am currently working on creating virtual IoT devices that can be used and placed inside the Unity3D editor. 我目前正在创建可在Unity3D编辑器中使用和放置的虚拟IoT设备。 This would allow me to have switches and buttons that can control real world smart lights using Mozilla's IoT router framework. 这将使我拥有可以使用Mozilla的IoT路由器框架控制现实世界中的智能灯的开关和按钮。 They have code for creating fake IoT devices for python, java, and c++ but nothing for C#. 他们具有用于为python,java和c ++创建伪造的IoT设备的代码,但对于C#则没有。 So I began working on porting the code over and quickly ran into my first issue. 因此,我开始着手移植代码,并很快遇到了我的第一个问题。 Their example programs register a DNS service I am not quite sure why I am assuming its the way the server code actually works but barring my lack of knowledge on that side I need to be able to register a DNS service on C#. 他们的示例程序注册了DNS服务,但我不太确定为什么要以服务器代码的实际工作方式为准,但是除非我对此不了解,否则我需要能够在C#上注册DNS服务。 I am a complete noobie in this area and havent done anything with DNS before and am also pretty inexperienced with C# as well. 我在这方面是一个完全的菜鸟,以前从未使用DNS做过任何事情,并且对C#也不熟悉。 Just bear with me please though I am a fast learner and would really love to see this project work. 尽管我是一个学习速度很快的人,但请忍受我,真的很希望看到这个项目的工作。 So to start does anyone have an idea how to register a DNS service with C#? 因此,从一开始,有谁知道如何使用C#注册DNS服务?

Here is what the python code looks like that registers the service. 这是注册服务的python代码的样子。

self.service_info = ServiceInfo(
            '_webthing._tcp.local.',
            '{}._webthing._tcp.local.'.format(self.name),
            address=socket.inet_aton(get_ip()),
            port=self.port,
            properties={
                'path': '/',
            },
            server='{}.local.'.format(socket.gethostname()))
self.zeroconf = Zeroconf()
self.zeroconf.register_service(self.service_info)

Here is what the Java code looks like that registers the service. 这是注册服务的Java代码。

ServiceInfo serviceInfo = ServiceInfo.create("_webthing._tcp.local",
                                                     this.name,
                                                     null,
                                                     this.port,
                                                     "path=/");
this.jmdns.registerService(serviceInfo);

visit https://docs.microsoft.com/en-us/dotnet/api/system.net.dns?view=netframework-4.8 It could be efficient. 请访问https://docs.microsoft.com/zh-cn/dotnet/api/system.net.dns?view=netframework-4.8这可能是有效的。 The following example queries the DNS database for information on the host www.contoso.com 以下示例查询DNS数据库以获取有关主机www.contoso.com的信息

 IPHostEntry hostInfo = Dns.GetHostEntry("www.contoso.com");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM