Exemplo n.º 1
0
func simpleSend(t *testing.T, tx mangos.Socket, wg *sync.WaitGroup) {
	var buf [256]byte
	i := 0
	for i = 0; i < 10000; i++ {
		l := rand.Intn(255) + 1
		buf[0] = uint8(l)
		if e := tx.Send(buf[:l]); e != nil {
			t.Fatalf("Send: %v", e)
			break
		}
	}
	t.Logf("Sent %d Msgs", i)
	if e := tx.Close(); e != nil {
		t.Fatalf("Tx Close: %v", e)
	}
	wg.Done()
}
Exemplo n.º 2
0
func node1(url string, msg string) {
	var sock mangos.Socket
	var err error

	if sock, err = push.NewSocket(); err != nil {
		die("can't get new push socket: %s", err.Error())
	}
	sock.AddTransport(ipc.NewTransport())
	sock.AddTransport(tcp.NewTransport())
	if err = sock.Dial(url); err != nil {
		die("can't dial on push socket: %s", err.Error())
	}
	fmt.Printf("NODE1: SENDING \"%s\"\n", msg)
	if err = sock.Send([]byte(msg)); err != nil {
		die("can't send message on push socket: %s", err.Error())
	}
	sock.Close()
}
Exemplo n.º 3
0
func clientWorker(url string, id int) {
	var sock mangos.Socket
	var m *mangos.Message
	var err error

	if sock, err = req.NewSocket(); err != nil {
		die("can't get new req socket: %s", err.Error())
	}

	// Leave this in Cooked mode!

	sock.AddTransport(ipc.NewTransport())
	sock.AddTransport(tcp.NewTransport())
	if err = sock.Dial(url); err != nil {
		die("can't dial on req socket: %s", err.Error())
	}

	// send an empty messsage
	m = mangos.NewMessage(1)
	if err = sock.SendMsg(m); err != nil {
		die("can't send request: %s", err.Error())
	}

	if m, err = sock.RecvMsg(); err != nil {
		die("can't recv reply: %s", err.Error())
	}
	sock.Close()

	if len(m.Body) != 4 {
		die("bad response len: %d", len(m.Body))
	}

	worker := binary.BigEndian.Uint32(m.Body[0:])

	L.Lock()
	fmt.Printf("Client: %4d   Server: %4d\n", id, worker)
	L.Unlock()
}
Exemplo n.º 4
0
func node1(url string) {
	var sock mangos.Socket
	var err error
	var msg []byte

	if sock, err = req.NewSocket(); err != nil {
		die("can't get new req socket: %s", err.Error())
	}
	sock.AddTransport(ipc.NewTransport())
	sock.AddTransport(tcp.NewTransport())
	if err = sock.Dial(url); err != nil {
		die("can't dial on req socket: %s", err.Error())
	}
	fmt.Printf("NODE1: SENDING DATE REQUEST %s\n", "DATE")
	if err = sock.Send([]byte("DATE")); err != nil {
		die("can't send message on push socket: %s", err.Error())
	}
	if msg, err = sock.Recv(); err != nil {
		die("can't receive date: %s", err.Error())
	}
	fmt.Printf("NODE1: RECEIVED DATE %s\n", string(msg))
	sock.Close()
}
Exemplo n.º 5
0
func simpleRecv(t *testing.T, rx mangos.Socket, wg *sync.WaitGroup) {
	i := 0
	for i = 0; i < 10000; i++ {
		buf, e := rx.Recv()
		if e != nil {
			t.Fatalf("Recv: %v", e)
			break
		}
		if len(buf) < 1 {
			t.Fatalf("Recv: empty buf")
			break
		}
		if len(buf) != int(buf[0]) {
			t.Fatalf("Recv: length %d != expected %d",
				len(buf), buf[0])
			break
		}
	}
	t.Logf("Recvd %d Msgs", i)
	if e := rx.Close(); e != nil {
		t.Fatalf("Rx Close: %v", e)
	}
	wg.Done()
}