Esempio n. 1
0
func main() {
	var err error
	var nnzbus *nn.Socket
	pid := os.Getpid()

	var isServer bool = false
	if len(os.Args) > 1 && os.Args[1] == "--server" {
		isServer = true
	}

	if isServer {
		// server code, binds the bus to start it.
		nnzbus, err = nn.NewSocket(nn.AF_SP, nn.REP)
		if err != nil {
			log.Fatal(err)
		}
		defer nnzbus.Close()

		startZBus(nnzbus, ZBUS_ADDR)
		recvMsgOnZBus(nnzbus)
		sendZDate(nnzbus)

	} else {
		// client code, connects to the bus.
		nnzbus, err = nn.NewSocket(nn.AF_SP, nn.REQ)
		if err != nil {
			log.Fatal(err)
		}
		defer nnzbus.Close()

		if _, err = nnzbus.Connect(ZBUS_ADDR); err != nil {
			log.Fatal(err)
		}

		sayHello(nnzbus)
		recvZDate(nnzbus)
	}

	fmt.Printf("[pid %d] done.\n", pid)
}
Esempio n. 2
0
// make addr separate from ZBUS_ADDR, so we
// can validate that the test detects a problem
// when they are different.
func ServerBindHelper(t *testing.T, addr_use string, addr_expect string) {
	nnzbus, err := nn.NewSocket(nn.AF_SP, nn.PAIR)
	if err != nil {
		t.Fatal(err)
	}
	defer nnzbus.Close()

	startZBus(nnzbus, addr_use)

	found := PortIsListenedOn(t, addr_expect)

	if !found {
		t.Logf("gozbus server was not listening on %v as expected", addr_expect)
		panic("no gozbus server at expected endpoint")
	}
}