Ejemplo n.º 1
0
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: rpcreader [-s] tcp-addr\n")
		flag.PrintDefaults()
		os.Exit(2)
	}
	flag.Parse()
	if flag.NArg() != 1 {
		flag.Usage()
		return
	}
	addr := flag.Arg(0)
	if *server {
		srv, err := ncrpc.NewServer(false)
		if err != nil {
			log.Fatal("ncrpc NewServer failed: ", err)
		}
		srv.RPCServer.Register(&Server{exp: srv.Exporter})
		lis, err := net.Listen("tcp", addr)
		if err != nil {
			log.Fatal("listen failed: ", err)
		}
		srv.Exporter.Serve(lis)
		return
	}
	client, err := ncrpc.Import("tcp", addr)
	if err != nil {
		log.Fatal("dial failed: ", err)
	}
	interact(client)
}
Ejemplo n.º 2
0
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: share [options] tcp-addr\n")
		flag.PrintDefaults()
		os.Exit(2)
	}
	flag.Parse()
	if flag.NArg() != 1 {
		flag.Usage()
		return
	}
	addr := flag.Arg(0)
	if *server {
		ncsrv, err := ncrpc.NewServer(true)
		ncsrv.RPCServer.Register(&Server{ncsrv})
		lis, err := net.Listen("tcp", addr)
		if err != nil {
			log.Fatal("listen failed: ", err)
		}
		ncsrv.Exporter.Serve(lis)
		return
	}

	client, err := ncrpc.Import("tcp", addr)
	if err != nil {
		log.Fatal("dial failed: ", err)
	}
	rpcsrv := rpc.NewServer()
	rpcsrv.Register(Client{})
	err = client.Serve(*clientName, rpcsrv)
	if err != nil {
		log.Fatal("client.Serve failed: ", err)
	}
	interact(client.Server)
}