rustedbones / scout

Zeroconf for scala (multicast DNS service discovery)

Version Matrix

scout

Continuous Integration Maven Central Software License

Zeroconf for scala (multicast DNS service discovery)

Versions

Version Release date cats version Scala versions
0.1.0 2021-01-13 2.2.0 2.13.4, 2.12.12

Getting scout

libraryDependencies += "fr.davit" %% "scout" % "<version>"

Zeroconf

import cats.effect.{ContextShift, IO, Timer}
import fr.davit.scout.Zeroconf
import fr.davit.taxonomy.model.DnsMessage
import fr.davit.taxonomy.scodec.DnsCodec
import scodec.Codec

import java.net.InetAddress
import scala.concurrent.ExecutionContext
import scala.concurrent.duration._

implicit val contextShift: ContextShift[IO] = IO.contextShift(ExecutionContext.global)
implicit val timer: Timer[IO]               = IO.timer(ExecutionContext.global)

// service definition
val service = Zeroconf.Service("ipp", "tcp")

// Scanning for service instances
val instances = Zeroconf
  .scan[IO](service)
  .interruptAfter(50.seconds)
  .compile
  .toList
  .unsafeRunSync()


// instance definition
val instance = Zeroconf.Instance(
  service = service,
  name = "Ed’s Party Mix",
  port = 1010,
  target = "eds-musicbox", 
  information = Map("codec" -> "ogg"),
  addresses = Seq(InetAddress.getByName("169.254.150.84")) // use local address when left empty
)

// Registering an instance
Zeroconf.register[IO](instance)