Пример #1
0
// ServeEchoService serves the given EchoService implementation on conn.
func ServeEchoService(conn io.ReadWriteCloser, x EchoService) error {
	srv := rpc.NewServer()
	if err := srv.RegisterName("EchoService", x); err != nil {
		return err
	}
	srv.ServeCodec(protorpc.NewServerCodec(conn))
	return nil
}
Пример #2
0
// ListenAndServeEchoService listen announces on the local network address laddr
// and serves the given EchoService implementation.
func ListenAndServeEchoService(network, addr string, x EchoService) error {
	clients, err := net.Listen(network, addr)
	if err != nil {
		return err
	}
	srv := rpc.NewServer()
	if err := srv.RegisterName("EchoService", x); err != nil {
		return err
	}
	for {
		conn, err := clients.Accept()
		if err != nil {
			return err
		}
		go srv.ServeCodec(protorpc.NewServerCodec(conn))
	}
	panic("unreachable")
}
Пример #3
0
func listenAndServeArithAndEchoService(network, addr string) error {
	clients, err := net.Listen(network, addr)
	if err != nil {
		return err
	}
	srv := rpc.NewServer()
	if err := RegisterArithService(srv, new(Arith)); err != nil {
		return err
	}
	if err := RegisterEchoService(srv, new(Echo)); err != nil {
		return err
	}
	for {
		conn, err := clients.Accept()
		if err != nil {
			return err
		}
		go srv.ServeCodec(protorpc.NewServerCodec(conn))
	}
	panic("unreachable")
}
Пример #4
0
func main() {
	ln, err := net.Listen("tcp", "127.0.0.1:1234")
	if err != nil {
		log.Fatalln(err)
	}
	srv := rpc.NewServer()
	if err := service.RegisterArithService(srv, new(Arith)); err != nil {
		log.Fatalln(err)
	}
	if err := service.RegisterEchoService(srv, new(Echo)); err != nil {
		log.Fatalln(err)
	}
	for {
		conn, err := ln.Accept()
		if err != nil {
			log.Fatalln(err)
		}
		go srv.ServeCodec(protorpc.NewServerCodec(conn))
	}
	panic("unreachable")
}