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


Golang Socket.Connect方法代码示例

本文整理汇总了Golang中github.com/kildevaeld/projects/Godeps/_workspace/src/github.com/pebbe/zmq4.Socket.Connect方法的典型用法代码示例。如果您正苦于以下问题:Golang Socket.Connect方法的具体用法?Golang Socket.Connect怎么用?Golang Socket.Connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/kildevaeld/projects/Godeps/_workspace/src/github.com/pebbe/zmq4.Socket的用法示例。


在下文中一共展示了Socket.Connect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: NewPubsubClient

func NewPubsubClient(config PubsubConfig) (*PubsubClient, error) {

	context, err := zmq4.NewContext()
	var pub *zmq4.Socket
	var sub *zmq4.Socket

	if err != nil {
		return nil, err
	}

	if sub, err = context.NewSocket(zmq4.SUB); err != nil {
		return nil, err
	}

	if pub, err = context.NewSocket(zmq4.PUSH); err != nil {
		return nil, err
	}

	if err = pub.Connect(config.PubAddress); err != nil {

		return nil, err
	}

	if err = sub.Connect(config.SubAddress); err != nil {
		return nil, err
	}

	return &PubsubClient{pub, sub}, nil

}
开发者ID:kildevaeld,项目名称:projects,代码行数:30,代码来源:client.go

示例2: Example_test_hwm

func Example_test_hwm() {

	MAX_SENDS := 10000
	BIND_FIRST := 1
	CONNECT_FIRST := 2

	test_defaults := func() int {

		// Set up bind socket
		bind_socket, err := zmq.NewSocket(zmq.PULL)
		if checkErr(err) {
			return 0
		}
		defer func() {
			err := bind_socket.Close()
			checkErr(err)
		}()

		err = bind_socket.Bind("inproc://a")
		if checkErr(err) {
			return 0
		}

		// Set up connect socket
		connect_socket, err := zmq.NewSocket(zmq.PUSH)
		if checkErr(err) {
			return 0
		}
		defer func() {
			err := connect_socket.Close()
			checkErr(err)
		}()

		err = connect_socket.Connect("inproc://a")
		if checkErr(err) {
			return 0
		}

		// Send until we block
		send_count := 0
		for send_count < MAX_SENDS {
			_, err := connect_socket.Send("", zmq.DONTWAIT)
			if err != nil {
				break
			}
			send_count++
		}

		// Now receive all sent messages
		recv_count := 0
		for {
			_, err := bind_socket.Recv(zmq.DONTWAIT)
			if err != nil {
				break
			}
			recv_count++
		}
		fmt.Println("send_count == recv_count:", send_count == recv_count)

		return send_count
	}

	count_msg := func(send_hwm, recv_hwm, testType int) int {

		var bind_socket, connect_socket *zmq.Socket
		var err error

		if testType == BIND_FIRST {
			// Set up bind socket
			bind_socket, err = zmq.NewSocket(zmq.PULL)
			if checkErr(err) {
				return 0
			}
			defer func() {
				err := bind_socket.Close()
				checkErr(err)
			}()

			err = bind_socket.SetRcvhwm(recv_hwm)
			if checkErr(err) {
				return 0
			}

			err = bind_socket.Bind("inproc://a")
			if checkErr(err) {
				return 0
			}

			// Set up connect socket
			connect_socket, err = zmq.NewSocket(zmq.PUSH)
			if checkErr(err) {
				return 0
			}
			defer func() {
				err := connect_socket.Close()
				checkErr(err)
			}()

			err = connect_socket.SetSndhwm(send_hwm)
			if checkErr(err) {
//.........这里部分代码省略.........
开发者ID:kildevaeld,项目名称:projects,代码行数:101,代码来源:zmq4_test.go


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