55 lines
1.8 KiB
Markdown
55 lines
1.8 KiB
Markdown
# peerdiscovery
|
|
|
|
[](https://travis-ci.org/schollz/peerdiscovery)
|
|
[](https://goreportcard.com/report/github.com/schollz/peerdiscovery)
|
|
[](https://gocover.io/github.com/schollz/peerdiscovery)
|
|
[](https://godoc.org/github.com/schollz/peerdiscovery)
|
|
|
|
Pure-go library for cross-platform thread-safe local peer discovery using UDP broadcast. I needed to use peer discovery for [croc](https://github.com/schollz/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.
|
|
|
|
```golang
|
|
discoveries, _ := peerdiscovery.Discover(peerdiscovery.Settings{Limit: 1})
|
|
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 2:**
|
|
|
|

|
|
|
|
For more examples, see [the scanning example](https://github.com/schollz/peerdiscovery/blob/master/examples/main.go) or [the docs](https://godoc.org/github.com/schollz/peerdiscovery).
|
|
|
|
|
|
## Contributing
|
|
|
|
Pull requests are welcome. Feel free to...
|
|
|
|
- Revise documentation
|
|
- Add new features
|
|
- Fix bugs
|
|
- Suggest improvements
|
|
|
|
## License
|
|
|
|
MIT
|