Esempio n. 1
0
func NewDiscoverer(id string, addresses []string) (*Discoverer, error) {
	disc := &Discoverer{
		myID:            id,
		listenAddrs:     addresses,
		localBcastIntv:  30 * time.Second,
		globalBcastIntv: 1800 * time.Second,
		beacon:          mc.NewBeacon("239.21.0.25", 21025),
		registry:        make(map[string][]string),
	}

	go disc.recvAnnouncements()

	return disc, nil
}
Esempio n. 2
0
func main() {
	b := mc.NewBeacon("239.21.0.25", 21025)
	go func() {
		for {
			bs, addr := b.Recv()
			log.Printf("Received %d bytes from %s: %x %x", len(bs), addr, bs[:8], bs[8:])
		}
	}()
	go func() {
		bs := [16]byte{}
		binary.BigEndian.PutUint64(bs[:], uint64(time.Now().UnixNano()))
		log.Printf("My ID: %x", bs[:8])
		for {
			binary.BigEndian.PutUint64(bs[8:], uint64(time.Now().UnixNano()))
			b.Send(bs[:])
			log.Printf("Sent %d bytes", len(bs[:]))
			time.Sleep(10 * time.Second)
		}
	}()
	select {}
}