I modify wuserver.go to test pub-sub in same process, and catch net packets with wireshark.
The socket can be established, but sub can't receive any message?
how can I make it works?
package main
import (
zmq "github.com/pebbe/zmq4"
"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")
sub, _ := zmq.NewSocket(zmq.SUB)
sub.Connect("tcp://localhost:5556")
go func() {
for {
fmt.Println("sub")
msg, _ := sub.Recv(0)
fmt.Println(msg)
time.Sleep(time.Second)
}
}()
// Initialize random number generator
rand.Seed(time.Now().UnixNano())
// loop for a while aparently
go func() {
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)
fmt.Println("publish: %s", msg)
publisher.Send(msg, zmq.DONTWAIT)
time.Sleep(time.Second)
}
}()
for {
}
}
I modify wuserver.go to test pub-sub in same process, and catch net packets with wireshark. The socket can be established, but sub can't receive any message? how can I make it works?