Пример #1
0
func (st *subTest) Init(t *testing.T, addr string) bool {
	var err error
	if st.Sock, err = sub.NewSocket(); err != nil {
		st.Errorf("NewSocket(): %v", err)
		return false
	}
	rv := st.T.Init(t, addr)
	// We have to subscribe to the START message!
	if !rv {
		return false
	}
	err = st.Sock.SetOption(mangos.OptionSubscribe, []byte("START"))
	if err != nil {
		st.Errorf("Failed subscription to START: %v", err)
		return false
	}

	err = st.Sock.SetOption(mangos.OptionSubscribe, []byte("END"))
	if err != nil {
		st.Errorf("Failed to subscribe to END: %v", err)
		return false
	}

	err = st.Sock.SetOption(mangos.OptionSubscribe, []byte("/rain"))
	if err != nil {
		st.Errorf("Failed subscribing to the rain: %v", err)
		return false
	}

	return true
}
Пример #2
0
func client(url string, name string) {
	var sock mangos.Socket
	var err error
	var msg []byte

	if sock, err = sub.NewSocket(); err != nil {
		die("can't get new sub socket: %s", err.Error())
	}
	sock.AddTransport(ipc.NewTransport())
	sock.AddTransport(tcp.NewTransport())
	if err = sock.Dial(url); err != nil {
		die("can't dial on sub socket: %s", err.Error())
	}
	// Empty byte array effectively subscribes to everything
	err = sock.SetOption(mangos.OptionSubscribe, []byte(""))
	if err != nil {
		die("cannot subscribe: %s", err.Error())
	}
	for {
		if msg, err = sock.Recv(); err != nil {
			die("Cannot recv: %s", err.Error())
		}
		fmt.Printf("CLIENT(%s): RECEIVED %s\n", name, string(msg))
	}
}