Exemple #1
0
func main() {

	var s2 *nn.Socket
	var err error
	if s2, err = nn.NewSocket(nn.AF_SP, nn.PAIR); err != nil {
		panic(err)
	}
	if _, err = s2.Connect(addr); err != nil {
		panic(err)
	}

	buf := []byte("hello jason")
	t0 := time.Now()
	N := 10
	for i := 0; i < N; i++ {
		if _, err = s2.Send(buf, 0); err != nil {
			panic(err)
		}
		if _, err := s2.Recv(0); err != nil {
			panic(err)
		}
	}

	if err = s2.Close(); err != nil {
		panic(err)
	}
	fmt.Printf("cli done. elap: %v\n", time.Since(t0))
}
Exemple #2
0
func main() {

	var err error
	var s *nn.Socket
	if s, err = nn.NewSocket(nn.AF_SP, nn.PAIR); err != nil {
		panic(err)
	}
	if _, err = s.Bind(addr); err != nil {
		panic(err)
	}
	fmt.Printf("serv bound '%s'\n", addr)

	t0 := time.Now()
	//N := 100
	for {
		data, err := s.Recv(0)
		fmt.Printf("serv received data: '%s'\n", data)
		if err != nil {
			panic(err)
		}

		// echo data back
		if _, err = s.Send(data, 0); err != nil {
			panic(err)
		}
	}

	if err = s.Close(); err != nil {
		panic(err)
	}
	fmt.Printf("elap: %v\n", time.Since(t0))

	select {}
}