Swiftpack.co - Package - Bouke/NetService

Pure Swift NetService (Bonjour / Zeroconf / mDNS) implementation

Build Status

This module allows you to publish your own Bonjour service on the local network. On macOS NetService is included with Cocoa, however on Linux there's no such thing in the standard library.

Since version 0.5 this library uses dns_sd as the responder, instead of implementing mDNS itself. On macOS this means that it uses the system-wide daemon, and on Linux one should install libavahi-compat-libdnssd-dev to run the system-wide daemon.


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 = ...
withExtendedLifetime((service, delegate)) {

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)) {


This library was written by Bouke Haarsma.


Stars: 88


Used By

Total: 0


- 2019-08-31 08:54:23


  • Swift 4 support.

Swift 5 support - 2019-03-31 20:38:33

Backed by dns_sd - 2019-01-05 15:12:48

This version replaces the mDNS resolver with the system library providing dns_sd. On Linux you can install Avahi: libavahi-compat-libdnssd-dev, on macOS it will use the builtin mDNS resolver.


  • Use Avahi resolver on Linux.

- 2018-12-09 08:21:27


  • Default delegate implementations

- 2018-10-21 06:15:08


  • Better error handling

Swift 4.2 - 2018-10-21 06:14:57


  • Swift 4.2