native-mdns
0.1.3indexedmDNS announcer supporting broadcast-only service registration with A/PTR/SRV/TXT records, configurable hostname/IP/port/TXT, event hooks, AirPlay2 example, periodic broadcast and C/C++ shared-lib bindings.
mDNS announcer supporting broadcast-only service registration with A/PTR/SRV/TXT records, configurable hostname/IP/port/TXT, event hooks, AirPlay2 example, periodic broadcast and C/C++ shared-lib bindings.
A Kotlin multiplatform library for mdns announcer(mdns server), only broadcast is supported,
Also, nmdns can be compiled to shared/static lib for other languages calling, see c++ example
mDNS is usually used for Apple's AirPlay protocol family, there's an example in README.md How to use
Supported platforms:
Platform implementations are based on:
java.net.MulticastSocketNo external dependencies required.
Supported record type
Supported features
AAAA is not supported
AirPlay2(_airplay._tcp.local.) is tested
Make sure you added the mavenCentral repository in your project
kotlin {
linuxX64()
// Add other platforms
sourceSets {
commonMain.dependencies {
implementation("cn.rtast.nmdns:native-mdns:<version>")
}
}
}
There is a simple airplay2 service
val service = registerService(
serviceType = "_airplay._tcp.local.",
serviceName = "AP@RTAST",
hostname = "rtakland.local.",
ipAddress = "192.168.10.104",
port = ,
bindAddress = ,
mdnsPort = ,
txtRecords = listOf(, )
) {
onBroadcast {
println()
}
onRegister {
println()
}
onUnregistered {
println()
}
}
() {
service.broadcast()
delay()
}
volatile sig_atomic_t keepRunning = 1;
void handle_sigint(int sig) {
std::printf("\nCaught signal %d, exiting...\n", sig);
keepRunning = 0;
}
int main() {
libnmdns_kref_kotlin_collections_List txt = create_txt_records();
add_txt_record(txt, "deviceid=ef:42:0d:76:f1:97");
add_txt_record(txt, "model=AppleTV3,2C");
add_txt_record(txt, "features=0x5A7FFFF7,0x1E");
add_txt_record(txt, "srcvers=220.68");
add_txt_record(txt, "pk=f3769a660475d27b4f6040381d784645e13e21c53e6d2da6a8c3d757086fc336");
libnmdns_kref_cn_rtast_nmdns_NMDNSAnnouncer service = register_service(
"_airplay._tcp.local.",
"AP@RTAST",
"rtakland.local.",
"192.168.10.104",
7001, 3652, "192.168.10.104",
txt
);
std::signal(SIGINT, handle_sigint);
std::signal(SIGTERM, handle_sigint);
std::signal(SIGHUP, handle_sigint);
std::signal(SIGQUIT, handle_sigint);
std::printf("Running... Press Ctrl+C to exit\n");
while (keepRunning) {
broadcast(service);
sleep1(2);
}
return 0;
}
Surfaced from shared tags and platforms — no rankings paid for.