Exemple #1
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
}
Exemple #2
0
func main() {
	context, _ := zmq.NewContext()
	socket, _ := context.NewSocket(zmq.REP)
	socket.Bind("tcp://127.0.0.1:5000")
	socket.Bind("tcp://127.0.0.1:6000")

	for {
		msg, _ := socket.Recv(0)
		println("Got", string(msg))
		socket.Send(msg, 0)
	}
}
Exemple #3
0
func main() {
	context, _ := zmq.NewContext()
	socket, _ := context.NewSocket(zmq.REQ)
	socket.Connect("tcp://127.0.0.1:5000")
	socket.Connect("tcp://127.0.0.1:6000")

	for i := 0; i < 10; i++ {
		msg := fmt.Sprintf("msg %d", i)
		socket.Send([]byte(msg), 0)
		println("Sending", msg)
		socket.Recv(0)
	}
}