本文整理汇总了Golang中github.com/alecthomas/gozmq.Socket.Bind方法的典型用法代码示例。如果您正苦于以下问题:Golang Socket.Bind方法的具体用法?Golang Socket.Bind怎么用?Golang Socket.Bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/alecthomas/gozmq.Socket
的用法示例。
在下文中一共展示了Socket.Bind方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: proxyRouting
func proxyRouting(status chan bool) {
// intialize the zmq context.
context, err := zmq.NewContext()
if err != nil {
status <- false
log.Fatal("Intialize the zeromq context failure.\n")
}
defer context.Close()
var subscriber, publisher *zmq.Socket
subscriber, err = context.NewSocket(zmq.XSUB)
if err != nil {
status <- false
log.Fatal("Intialize the subscriber failure.\n")
}
defer subscriber.Close()
var (
sub_address, pub_address = "*", "*"
subPort, pubPort = 6001, 6000
)
// Bind the subscriber
address := fmt.Sprintf("tcp://%s:%v", sub_address, subPort)
err = subscriber.Bind(address)
if err != nil {
status <- false
log.Fatalf("Subscriber bind on the address %s failure\n", address)
}
log.Printf("Subscriber bind on the address %s.\n", address)
publisher, err = context.NewSocket(zmq.XPUB)
if err != nil {
status <- false
log.Fatal("Intialize the publisher failure.\n")
}
defer publisher.Close()
// Bind the publisher
address = fmt.Sprintf("tcp://%s:%v", pub_address, pubPort)
err = publisher.Bind(address)
if err != nil {
status <- false
log.Fatalf("Publisher bind on the address %s failure.\n", address)
}
log.Printf("Publisher bind on the address %s.\n", address)
log.Println("Proxy successfully launched...")
// Poll the events on relevant sockets.
zmq.Proxy(subscriber, publisher, nil)
}