2016-02-24 23:15:28 +01:00
# mDns Module
2016-01-28 03:57:58 +01:00
2016-02-24 23:15:28 +01:00
[Multicast DNS ](https://en.wikipedia.org/wiki/Multicast_DNS ) is used as part of Bonjour / Zeroconf. This allows system to identify themselves and the services that they provide on a local area network. Clients are then able to discover these systems and connect to them.
2016-01-28 03:57:58 +01:00
## mdns.register()
2016-02-24 23:15:28 +01:00
Register a hostname and start the mDNS service. If the service is already running, then it will be restarted with the new parameters.
2016-01-28 03:57:58 +01:00
#### Syntax
`mdns.register(hostname, servicename, port [, attributes])`
#### Parameters
- `hostname` The hostname for this device. Alphanumeric characters are best.
2016-02-24 23:15:28 +01:00
- `servicename` The service name for this device. Alphanumeric characters are best. This will get prefixed with `_` and suffixed with `._tcp`
2016-01-28 03:57:58 +01:00
- `port` The port number for the primary service.
- `attributes` A optional table of up to 10 attributes to be exposed. The keys must all be strings.
#### Returns
2016-02-24 23:15:28 +01:00
`nil`
2016-01-28 03:57:58 +01:00
#### Errors
2016-02-24 23:15:28 +01:00
Various errors can be generated during argument validation. The NodeMCU must have an IP address at the time of the call, otherwise an error is thrown.
2016-01-28 03:57:58 +01:00
#### Example
mdns.register("fishtank", "http", 80, { hardware='NodeMCU'})
2016-02-24 23:15:28 +01:00
Using `dns-sd` on OS X, you can see `fishtank.local` as providing the `_http._tcp` service. You can also browse directly to `fishtank.local` . In Safari you can get all the mDNS web pages as part of your bookmarks menu.
2016-01-28 03:57:58 +01:00
## mdns.close()
2016-02-24 23:15:28 +01:00
Shut down the mDNS service. This is not normally needed.
2016-01-28 03:57:58 +01:00
#### Syntax
`mdns.close()`
2016-02-24 23:15:28 +01:00
#### Parameters
none
2016-01-28 03:57:58 +01:00
#### Returns
2016-02-24 23:15:28 +01:00
`nil`