Example #1
0
// PrepareSockets sets up the ZMQ sockets through which the kernel will communicate.
func PrepareSockets(connInfo ConnectionInfo) (SocketGroup, error) {

	// Initialize the Socket Group.
	context, sg, err := createSockets()
	if err != nil {
		return sg, errors.Wrap(err, "Could not initialize context and Socket Group")
	}

	// Bind the sockets.
	address := fmt.Sprintf("%v://%v:%%v", connInfo.Transport, connInfo.IP)
	sg.ShellSocket.Bind(fmt.Sprintf(address, connInfo.ShellPort))
	sg.ControlSocket.Bind(fmt.Sprintf(address, connInfo.ControlPort))
	sg.StdinSocket.Bind(fmt.Sprintf(address, connInfo.StdinPort))
	sg.IOPubSocket.Bind(fmt.Sprintf(address, connInfo.IOPubPort))

	// Message signing key
	sg.Key = []byte(connInfo.Key)

	// Start the heartbeat device
	HBSocket, err := context.NewSocket(zmq.REP)
	if err != nil {
		return sg, errors.Wrap(err, "Could not get the Heartbeat device socket")
	}
	HBSocket.Bind(fmt.Sprintf(address, connInfo.HBPort))
	go zmq.Device(zmq.FORWARDER, HBSocket, HBSocket)

	return sg, nil
}
Example #2
0
//---------------------------------------------------------------------------------------------------------------------
//   
//   AT 용 ZMQ 프록시 서버 앱이다. 
//   
//---------------------------------------------------------------------------------------------------------------------
func main() {

    fmt.Println( "Proxy Start..." )
	zmqContext, _ := zmq.NewContext()
    defer zmqContext.Close()
	
    sub, _ := zmqContext.NewSocket(zmq.SUB)
	defer sub.Close()
	
	pub, _ := zmqContext.NewSocket(zmq.PUB)
	defer pub.Close()

//	sub.Connect( "ipc:///tmp/at_frame_sub" )
//	pub.Connect( "ipc:///tmp/at_frame_pub" )
	pub.Bind( AF_ZMQ_PROXY_XPUB )

	sub.Bind( AF_ZMQ_PROXY_XSUB )
    sub.SetSubscribe("")	
	
	zmq.Device(zmq.FORWARDER, sub, pub )
//	for {
//		message, _ := sub.Recv(0)
//        fmt.Println( "Proxy Read Ok" );		
//		pub.Send(message, 0)
//	}
	
}
Example #3
0
func main() {
	context, _ := zmq.NewContext()
	defer context.Close()

	// Socket facing clients
	frontend, _ := context.NewSocket(zmq.ROUTER)
	defer frontend.Close()
	frontend.Bind("tcp://*:5559")

	// Socket facing services
	backend, _ := context.NewSocket(zmq.DEALER)
	defer backend.Close()
	backend.Bind("tcp://*:5560")

	// Start built-in device
	zmq.Device(zmq.QUEUE, frontend, backend)

	// We never get here...
}
Example #4
0
// PrepareSockets sets up the ZMQ sockets through which the kernel will communicate.
func PrepareSockets(conn_info ConnectionInfo) (sg SocketGroup) {
	context, _ := zmq.NewContext()
	sg.Shell_socket, _ = context.NewSocket(zmq.ROUTER)
	sg.Control_socket, _ = context.NewSocket(zmq.ROUTER)
	sg.Stdin_socket, _ = context.NewSocket(zmq.ROUTER)
	sg.IOPub_socket, _ = context.NewSocket(zmq.PUB)

	address := fmt.Sprintf("%v://%v:%%v", conn_info.Transport, conn_info.IP)

	sg.Shell_socket.Bind(fmt.Sprintf(address, conn_info.Shell_port))
	sg.Control_socket.Bind(fmt.Sprintf(address, conn_info.Control_port))
	sg.Stdin_socket.Bind(fmt.Sprintf(address, conn_info.Stdin_port))
	sg.IOPub_socket.Bind(fmt.Sprintf(address, conn_info.IOPub_port))

	// Message signing key
	sg.Key = []byte(conn_info.Key)

	// Start the heartbeat device
	HB_socket, _ := context.NewSocket(zmq.REP)
	HB_socket.Bind(fmt.Sprintf(address, conn_info.HB_port))
	go zmq.Device(zmq.FORWARDER, HB_socket, HB_socket)
	return
}
Example #5
0
func builtinDevice(dev *DeviceContext) {
	var (
		typ         zmq.DeviceType
		back, front zmq.Socket
		err         error
	)
	switch dev.Type() {
	case "zmq_forwarder":
		typ = zmq.FORWARDER
	case "zmq_streamer":
		typ = zmq.STREAMER
	case "zmq_queue":
		typ = zmq.QUEUE
	default:
		panic(fmt.Sprintf("device has unknown type: %s.", dev.Type()))
	}
	back = dev.MustOpen("backend")
	front = dev.MustOpen("frontend")
	err = zmq.Device(typ, front, back)
	//err = zmq.Proxy( front, back, capture)
	if err != nil {
	}
}
Example #6
0
func main() {
	args := parseArgs()

	done := make(chan bool, 1)

	context, _ := zmq.NewContext()
	defer context.Close()

	for _, arg := range args {
		go func(arg Arguments) {
			in, _ := context.NewSocket(zmq.XSUB)
			out, _ := context.NewSocket(zmq.XPUB)
			defer in.Close()
			defer out.Close()

			in.Connect("ipc://" + arg.Src)
			out.Connect("ipc://" + arg.Dest)

			zmq.Device(zmq.FORWARDER, in, out)
		}(arg)
	}

	<-done
}
Example #7
0
func main() {
	// Launch pool of worker threads
	for i := 0; i != 5; i = i + 1 {
		go worker()
	}

	// Prepare our context and sockets
	context, _ := zmq.NewContext()
	defer context.Close()

	// Socket to talk to clients
	clients, _ := context.NewSocket(zmq.ROUTER)
	defer clients.Close()
	clients.Bind("tcp://*:5555")

	// Socket to talk to workers
	workers, _ := context.NewSocket(zmq.DEALER)
	defer workers.Close()
	workers.Bind("ipc://workers.ipc")

	// connect work threads to client threads via a queue
	zmq.Device(zmq.QUEUE, clients, workers)

}
Example #8
0
func (b *Forwarder) Run() error {
	return zmq.Device(zmq.FORWARDER, b.frontend, b.backend)
}