Example #1
0
// Dial makes a connection to the named netchan service,
// which must have been previously exported with a call to Listen.
func Dial(imp *netchan.Importer, service string) (net.Conn, error) {
	cnames := make(chan string)
	err := imp.ImportNValues(service, cnames, netchan.Recv, 1, 1)
	if err != nil {
		return nil, err
	}
	clientName := <-cnames
	reqname := clientName + ".req"
	replyname := clientName + ".reply"
	req := make(chan []byte)
	err = imp.Import(reqname, req, netchan.Send, 200)
	if err != nil {
		return nil, err
	}
	reply := make(chan []byte)
	err = imp.Import(replyname, reply, netchan.Recv, 200)
	if err != nil {
		return nil, err
	}
	req <- []byte(initMessage)
	return &Conn{
		R:          reply,
		W:          req,
		chanReader: &chanReader{c: reply},
		chanWriter: &chanWriter{c: req},
		clientName: clientName,
		localAddr:  netchanAddr("unknown"),
		remoteAddr: netchanAddr(service),
		nc:         imp,
	}, nil
}
Example #2
0
File: main.go Project: qrush/go
func importReceive(imp *netchan.Importer) {
	ch := make(chan value)
	imp.ImportNValues("exportedSend", ch, netchan.Recv, new(value), count)
	for i := 0; i < count; i++ {
		v := <-ch
		fmt.Printf("%v\n", v)
		if v.i != 23+i || v.s != "hello" {
			fmt.Printf("importReceive: bad value: expected %d, hello; got %+v", 23+i, v)
		}
	}
}