我是zeroMQ的新手,我正在尝试创建一个服务器(带有绑定到本地端口的路由器套接字)和一个带有经销商套接字的客户端,该套接字连接到本地端口上的路由器套接字。客户端发送数据并退出,但路由器套接字上没有任何内容,即Recv(0)呼叫永久阻塞。服务器和客户端代码如下:
zmserver.go:
package main
import ("fmt"
zmq "github.com/pebbe/zmq4")
func main() {
fmt.Println("Starting server")
serversock, _ := zmq.NewSocket(zmq.ROUTER)
serversock.Bind("tcp://*:5050")
identity, _ := serversock.Recv(0)
fmt.Println(identity) //nothing is printed
fmt.Println(serversock.Recv(0)) //nothing is printed
fmt.Println(serversock.Recv(0)) //nothing is printed
}
zmclient.go:
package main
import ("fmt"
zmq "github.com/pebbe/zmq4")
func main(){
fmt.Println("Starting client")
clientsock, _ := zmq.NewSocket(zmq.DEALER)
defer clientsock.Close()
clientsock.SetIdentity("ID1")
clientsock.Connect("tcp://localhost:5050")
clientsock.Send("", zmq.SNDMORE)
clientsock.Send("Hi Boss", 0)
}