We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
server
package main import ( "fmt" "math/rand" "time" czmq "github.com/zeromq/goczmq" ) func main() { pubEndpoint := "tcp://*: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) } fmt.Println("send", msg) time.Sleep(time.Second * 10) } }
client
package main import ( "fmt" "strconv" "strings" czmq "github.com/zeromq/goczmq" ) func main() { pubEndpoint := "tcp://127.0.0.1:5556" filter := "" subSock, err := czmq.NewSub(pubEndpoint, filter) if err != nil { panic(err) } defer subSock.Destroy() fmt.Printf("Collecting updates from weather server for %s…\n", filter) subSock.Connect(pubEndpoint) for i := 0; i < 100; i++ { msg, _, err := subSock.RecvFrame() if err != nil { panic(err) } fmt.Println("recv msg", i, string(msg)) weatherData := strings.Split(string(msg), " ") temperature, err := strconv.ParseInt(weatherData[1], 10, 64) fmt.Println("recv temperature", temperature) } }
server output
send 5384 2 27 send 86137 -34 54 send 97726 52 41 send 12079 46 30 send 30493 126 29 send 98981 67 35 send 44885 105 47 send 73749 88 28 send 4384 53 34 send 64547 92 42 send 3616 -11 50 send 25786 -14 36
client output
recv msg 0 54425 55 16 recv temperature 55 recv msg 1 54425 55 16 recv temperature 55 recv msg 2 3300 -31 21 recv temperature -31 recv msg 3 3300 -31 21 recv temperature -31 recv msg 4 28162 64 38 recv temperature 64 recv msg 5 28162 64 38 recv temperature 64
The text was updated successfully, but these errors were encountered:
server output send 98081 -43 57 send 84059 -79 28 send 54425 55 16 send 3300 -31 21 send 28162 64 38 send 33274 106 55 send 23237 41 55 send 65466 48 18
client outpub Collecting updates from weather server for … recv msg 0 54425 55 16 recv temperature 55 recv msg 1 54425 55 16 recv temperature 55 recv msg 2 3300 -31 21 recv temperature -31 recv msg 3 3300 -31 21 recv temperature -31 recv msg 4 28162 64 38 recv temperature 64 recv msg 5 28162 64 38 recv temperature 64 recv msg 6 33274 106 55 recv temperature 106 recv msg 7 33274 106 55 recv temperature 106 recv msg 8 23237 41 55 recv temperature 41 recv msg 9 23237 41 55 recv temperature 41 recv msg 10 65466 48 18 recv temperature 48 recv msg 11 65466 48 18 recv temperature 48
Sorry, something went wrong.
No branches or pull requests
server
client
server output
client output
The text was updated successfully, but these errors were encountered: