I wrote a library (schollz/peerdiscovery) for discovering peers on a local network. I've tested it between a wireless ubuntu laptop and a wired ubuntu server and it works great.
go get github.com/schollz/peerdiscovery
cd $GOPATH/src/github.com/schollz/peerdiscovery/examples
go run broadcast.go
After both are run, both computers will discover each other and the associated payload (in the example its a random payload), and they will output something like:
2018/04/22 23:59:11 discovered ip '192.168.XX.XX' with payload 'YY'
But...this doesn't work on Windows! I have no idea
why. If one of the computers is a Windows computer there is no activity,
and no errors. I put in logging and found that Windows will get to the ReadFromUDP(buffer)
and then it is unable to read anything, ever and its sent packets aren't reaching the other computers.
golang.org/x/net/ipv4
, for some reason the pkg/net
ReadFromUDP
just didn't work.