Exemplo n.º 1
0
func main() {
	var straddr string
	flag.StringVar(&straddr, "a", "", "Address of the exporter")
	flag.Parse()
	if straddr == "" {
		flag.Usage()
		log.Exit("No address given")
	}
	bstdin := bufio.NewReader(os.Stdin)
	var err os.Error
	done := make(chan os.Error)
	imp, err := netchan.NewImporter("tcp", straddr)
	if err != nil {
		log.Exit("Error creating importer: ", err)
	}
	go func() {
		for line, err := bstdin.ReadString('\n'); err == nil; line, err = bstdin.ReadString('\n') {
			go importChan(imp, strings.TrimSpace(line), done)
			go func() {
				err := <-done
				log.Println(err)
			}()
		}
		log.Exit("Error reading stdin: ", err)
	}()
	<-done
}
Exemplo n.º 2
0
// NewClient makes a netchan connection from the given connection,
// imports the rpc service from that, and returns both in a new Client
// instance.  It assumes that the server has been started with Server.
func NewClient(conn io.ReadWriter) (*Client, error) {
	imp := netchan.NewImporter(conn)
	srvconn, err := ncnet.Dial(imp, "ncrpc.ctl")
	if err != nil {
		return nil, err
	}
	return &Client{imp, rpc.NewClient(srvconn)}, nil
}
Exemplo n.º 3
0
Arquivo: main.go Projeto: qrush/go
func main() {
	fmt.Println("I WILL FIND MY PARENTS")
	imp, ierr := netchan.NewImporter("tcp", ":9292")
	fmt.Println(ierr)
	c := make(chan os.Error)
	err := imp.Import("octocator", c, netchan.Recv, new(os.Error))
	fmt.Println(err)

	if err == nil {
		cat := <-c
		fmt.Println(cat)
	}
}
Exemplo n.º 4
0
func (n *NetChanOut) Run() {
	ticker := time.NewTicker(second)
	var val float64
	n.out = make(chan string)
	imp, _ := nt.NewImporter("tcp", "localhost:9090")
	imp.Import("Output", n.out, nt.Send)
	for {
		select {
		case val = <-n.in:
		case <-ticker.C:
			n.out <- fmt.Sprintf("%f\n", val)
		}
	}
	//create string netchan and print values over that chan
}
Exemplo n.º 5
0
func MakeImporterWithRetry(network string, remoteaddr string, n int, log logflow.Logger) *netchan.Importer {
	if log == nil {
		log = logflow.NewSource("util")
	}
	var err os.Error
	for i := 0; i < n; i++ {
		conn, err := net.Dial(network, "", remoteaddr)
		if err == nil {
			return netchan.NewImporter(conn)
		}
		log.Print("Netchan import failed, retrying")
		time.Sleep(1e9 / 2)
	}
	log.Print("Netchan import failed ", n, " times. Bailing out.")
	log.Fatal(err)
	return nil
}
Exemplo n.º 6
0
func outChanFactory() (chan value, os.Error){
	//Create and initialize the import channel
	imp, err := netchan.NewImporter("tcp","127.0.0.1:2346")
	lt();fmt.Println("New outgoing connection: 127.0.0.1:2346")
	if err != nil {
		return nil, err
	}
	lt();fmt.Println("outgoing importFactory Channel Made")
	//Make the outgoing communication channel for this program
	ch := make(chan value)
	//Link the ch channel to the import channel
	err = imp.Import("exportChannelRecv",ch,netchan.Send,new(value))
	if err != nil {
		return nil, err
	}
	return ch, err	
}
Exemplo n.º 7
0
func RunChannel() *chan int {
	exporter, err := netchan.NewImporter("tcp", "127.0.0.1:7000")
	s := make(chan int)
	if err != nil {
		panic(err.String())
	}
	srv_netchan := make(chan Message)
	err = exporter.Import("LCIMessenger", srv_netchan, netchan.Send)
	if err != nil {
		panic(err.String())
	}
	go func() {
		for {
			msg := Message{MsgServerInfo}
			srv_netchan <- msg
			break
		}
	}()
	return &s
}
Exemplo n.º 8
0
Arquivo: games.go Projeto: qrush/go
// Factory to make a proxy view implementation
func NewProxyView(name, local, remote string) (view View) {
	ls := strings.Split(local, ":", 0)
	rs := strings.Split(remote, ":", 0)

	view = new(ProxyView)
	view.(*ProxyView).name = name
	view.(*ProxyView).exp, _ = netchan.NewExporter("tcp", local)
	view.(*ProxyView).gotMove = make(chan bool)
	view.(*ProxyView).in = make(chan Move)
	view.(*ProxyView).out = make(chan Move)

	view.(*ProxyView).exp.Export(ls[1], view.(*ProxyView).out, netchan.Send, new(Move))
	for {
		var err os.Error
		if view.(*ProxyView).imp, err = netchan.NewImporter("tcp", remote); err != nil {
			time.Sleep(Second)
		} else {
			break
		}
	}
	view.(*ProxyView).imp.Import(rs[1], view.(*ProxyView).in, netchan.Recv, new(Move))
	return
}
Exemplo n.º 9
0
Arquivo: main.go Projeto: qrush/go
func main() {
	exp, _ := netchan.NewExporter("tcp", ":9292")
	imp, _ := netchan.NewImporter("tcp", ":9292")
	go exportSend(exp)
	importReceive(imp)
}