Exemple #1
0
func Setup() {
	config := config.Read()
	broadcastUri := fmt.Sprintf("tcp://%s:%d", config.Broadcaster.Host, config.Broadcaster.Port)

	var err error
	broadcaster, err = goczmq.NewPub(broadcastUri)
	if err != nil {
		panic(err)
	}
	log.Println("Broadcaster will start on", broadcastUri)

	pitcher = goczmq.NewSock(goczmq.Push)

	receiver, err = goczmq.NewPull("inproc://broadcast")
	if err != nil {
		panic(err)
	}

	helpers.ConnectToPeers(true, ConnectToBroadcatcher)
}
Exemple #2
0
func main() {
	pubEndpoint := "tcp://127.0.0.1:5556"
	pubSock, err := czmq.NewPub(pubEndpoint)
	if err != nil {
		panic(err)
	}

	defer pubSock.Destroy()
	pubSock.Bind(pubEndpoint)

	for {
		zipcode := rand.Intn(100000)
		temperature := rand.Intn(215) - 85
		relHumidity := rand.Intn(50) + 10

		msg := fmt.Sprintf("%d %d %d", zipcode, temperature, relHumidity)
		err := pubSock.SendFrame([]byte(msg), 0)
		if err != nil {
			panic(err)
		}
	}
}