Пример #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
// 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")
}