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


Golang Context.NewSocket方法代码示例

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


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

示例1: initial

// Tell the instance to initialize the information.
func (ep *Endpoint) initial(context *zmq.Context,
	act action, tp zmq.SocketType) error {

	if ep.sock != nil {
		return errors.New("Instance has already been initialized.")
	}

	// Check the pointer's validation.
	if context == nil {
		return errors.New("Specified context is null.")
	}

	var err error
	ep.sock, err = context.NewSocket(tp)
	if err != nil {
		return err
	}

	// Check the addrs' validation.
	for _, addr := range ep.Addr {
		if !addr.valid() {
			return ep.handleError(
				errors.New("Specified addr not valid."))
		}
		if err = act(addr); err != nil {
			return ep.handleError(err)
		}
	}

	return nil
}
开发者ID:ZhangzheBJUT,项目名称:notify,代码行数:32,代码来源:definition.go

示例2: runZmqStream

func runZmqStream() {
	var context zmq.Context
	var socket zmq.Socket

	// connect to zmq
	var err error
	if context, err = zmq.NewContext(); err != nil {
		panic("No ZMQ Context?")
	}
	defer context.Close()

	if socket, err = context.NewSocket(zmq.SUB); err != nil {
		panic("No ZMQ Socket Outbound??")
	}
	defer socket.Close()
	socket.Connect("tcp://localhost:5558")
	socket.SetSockOptString(zmq.SUBSCRIBE, "")

	for {
		// block here, waiting for inbound requests
		msg, _ := socket.Recv(0)
		if len(msg) > 0 {
			parts := strings.Split(string(msg), "\n\n")
			process(parts[0])
		}
	}
}
开发者ID:araddon,项目名称:sentiment,代码行数:27,代码来源:main.go

示例3: WorkerSocket

func WorkerSocket(context *zmq.Context) *zmq.Socket {
	worker, _ := context.NewSocket(zmq.DEALER)
	worker.Connect("tcp://localhost:5556")

	//  Tell queue we're ready for work
	fmt.Println("I: worker ready")
	worker.Send([]byte(PPP_READY), 0)
	return worker
}
开发者ID:Jay-Krish,项目名称:zguide,代码行数:9,代码来源:ppworker.go

示例4: openSocket

// Helper functions {{{
func openSocket(ctx zmq.Context, t zmq.SocketType, url string) zmq.Socket {
	socket, _ := ctx.NewSocket(t)
	if t == zmq.PUB || t == zmq.REP {
		socket.Bind(url)
	} else {
		socket.Connect(url)
	}
	return socket
}
开发者ID:pombredanne,项目名称:confsyncd,代码行数:10,代码来源:confsyncd.go

示例5: newBoundSocket

func newBoundSocket(context zmq.Context, address string, kind zmq.SocketType) zmq.Socket {
	socket, _ := context.NewSocket(kind)
	socket.Bind(address)
	return socket
}
开发者ID:mathieul,项目名称:goatd,代码行数:5,代码来源:tcp.go

示例6: ListenAndServe

// the listen and server for mongrel, expects an address like this
// @addr = string config parameter like this:
//    m2go.ListenAndServe("tcp://127.0.0.1:9555|tcp://127.0.0.1:9556|54c6755b-9628-40a4-9a2d-cc82a816345e", handler)
func ListenAndServe(addr string, handler http.Handler) {
	var Context zmq.Context
	var SocketIn zmq.Socket
	var SocketOut zmq.Socket
	var hasExited bool
	var err error

	m2addr := strings.Split(addr, "|") //

	log.Printf("m2go serving  %s\n", addr)

	/*
	  Connection to ZMQ setup
	*/
	connect := func() {
		if Context, err = zmq.NewContext(); err != nil {
			panic("No ZMQ Context?")
		}

		// listen for incoming requests
		if SocketIn, err = Context.NewSocket(zmq.PULL); err != nil {
			panic("No ZMQ Socket?")
		}
		SocketIn.Connect(m2addr[0])

		if SocketOut, err = Context.NewSocket(zmq.PUB); err != nil {
			panic("No ZMQ Socket Outbound??")
		}
		// outbound response on a different channel
		SocketOut.SetSockOptString(zmq.IDENTITY, m2addr[2])
		//socket.SetSockOptString(zmq.SUBSCRIBE, filter)
		SocketOut.Connect(m2addr[1])
	}

	connect()

	handleResponse := func(response []byte) {
		SocketOut.Send(response, 0)
	}
	stopper := func() {
		if !hasExited {
			hasExited = true
			SocketOut.Close()
			SocketIn.Close()
			Context.Close()
		}
	}
	defer stopper()

	for {
		// each inbound request
		m2data, err := SocketIn.Recv(0)
		//log.Println(string(m2data))
		if err != nil {
			log.Println("ZMQ Socket Input accept error ", err.Error())
		} else {
			go HandleM2Request(m2data, handleResponse, handler)
		}
	}
	log.Print("after close of runner")
}
开发者ID:araddon,项目名称:m2go,代码行数:64,代码来源:m2go.go


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