示例#1
0
// ServeAddService serves the given AddService backend implementation on conn.
func ServeAddService(conn net.Conn, backend AddService) error {
	srv := rpc.NewServer()
	if err := srv.RegisterName("AddService", backend); err != nil {
		return err
	}
	srv.ServeCodec(codec.NewServerCodec(conn))
	return nil
}
示例#2
0
// ServeLearner serves the given Learner backend implementation on conn.
func ServeLearner(conn net.Conn, backend Learner) error {
	srv := rpc.NewServer()
	if err := srv.RegisterName("Learner", backend); err != nil {
		return err
	}
	srv.ServeCodec(codec.NewServerCodec(conn))
	return nil
}
示例#3
0
// ListenAndServeAddService serves the given AddService backend implementation
// on all connections accepted as a result of listening on addr (TCP).
func ListenAndServeAddService(addr string, backend AddService) error {
	clients, err := net.Listen("tcp", addr)
	if err != nil {
		return err
	}
	srv := rpc.NewServer()
	if err := srv.RegisterName("AddService", backend); err != nil {
		return err
	}
	for {
		conn, err := clients.Accept()
		if err != nil {
			return err
		}
		go srv.ServeCodec(codec.NewServerCodec(conn))
	}
	panic("unreachable")
}