当前位置: 首页>>代码示例>>Golang>>正文


Golang Socket.Bind方法代码示例

本文整理汇总了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)
}
开发者ID:neutrous,项目名称:notify,代码行数:51,代码来源:proxy.go


注:本文中的github.com/alecthomas/gozmq.Socket.Bind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。