forked from pebbe/zmq3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wuserver.go
40 lines (31 loc) · 767 Bytes
/
wuserver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// Weather update server.
// Binds PUB socket to tcp://*:5556
// Publishes random weather updates
//
package main
import (
zmq "github.com/pebbe/zmq3"
"fmt"
"math/rand"
"time"
)
func main() {
// Prepare our publisher
publisher, _ := zmq.NewSocket(zmq.PUB)
defer publisher.Close()
publisher.Bind("tcp://*:5556")
publisher.Bind("ipc://weather.ipc")
// Initialize random number generator
rand.Seed(time.Now().UnixNano())
// loop for a while aparently
for {
// Get values that will fool the boss
zipcode := rand.Intn(100000)
temperature := rand.Intn(215) - 80
relhumidity := rand.Intn(50) + 10
// Send message to all subscribers
msg := fmt.Sprintf("%05d %d %d", zipcode, temperature, relhumidity)
publisher.Send(msg, 0)
}
}