croc/vendor/github.com/schollz/peerdiscovery/README.md

1.8 KiB

peerdiscovery

travis go report card coverage godocs

Pure-go library for cross-platform thread-safe local peer discovery using UDP broadcast. I needed to use peer discovery for croc and everything I tried had problems, so I made another one.

Install

Make sure you have Go 1.5+.

go get -u github.com/schollz/peerdiscovery

Usage

The following is a code to find the first peer on the local network and print it out.

p, _ := peerdiscovery.New(peerdiscovery.Settings{Limit: 1})
discoveries, _ := p.Discover()
for _, d := range discoveries {
    fmt.Printf("discovered '%s'\n", d.Address)
}

Here's the output when running on two computers. (Run these gifs in sync by hitting Ctl + F5).

Computer 1:

computer 1

Computer 2:

computer 1

For more examples, see the scanning example or the docs.

Contributing

Pull requests are welcome. Feel free to...

  • Revise documentation
  • Add new features
  • Fix bugs
  • Suggest improvements

License

MIT