Bouke/NetService
Swift NetService (Bonjour / Zeroconf / mDNS) implementation for Linux
Usage
See also NetService-Example. Note that like Apple's NetService, you need to run a RunLoop in order for the callbacks to happen.
There's also a command line tool included called dns-sd, with a subset of the functionality provided by Apple's tool with the same name. You can use this tool to verify the implementation and debug your network when advertisements are not working. Run swift run dns-sd --help for usage instructions.
Publish a NetService
This code will publish a new NetService advertising port 8000. Note that you need to setup a listening socket on port 8000 yourself.
import Foundation
import NetService
let service = NetService(domain: "local.", type: "_hap._tcp.", name: "Zithoek", port: 8000)
service.delegate = ...
service.publish()
withExtendedLifetime((service, delegate)) {
RunLoop.main.run()
}Browsing for NetServices
This code will start a search for the given service type.
let browser = NetServiceBrowser()
browser.delegate = ...
browser.searchForServices(ofType: "_airplay._tcp.", inDomain: "local.")
withExtendedLifetime((browser, delegate)) {
RunLoop.main.run()
}Credits
This library was written by Bouke Haarsma.
Package Metadata
Repository: Bouke/NetService
Stars: 121
Forks: 24
Open issues: 9
Default branch: master
Primary language: swift
License: MIT
Topics: bonjour, mdns, rfc-6762, swift, zeroconf
README: README.md