当前位置: 首页 > news >正文

安徽网站建设制作大数据营销

安徽网站建设制作,大数据营销,seo网站编辑,上海市住房和城乡建设厅官方网站一、服务端流式处理概述 客户端向服务端发送请求,服务端可以将多个消息流式传输回调用方和客户端流相反,客户端流发出请求,服务端可以传输一批消息给客户端,直至本次请求响应完全结束。针对文件分段传输下载,该方式非…

一、服务端流式处理概述

  1. 客户端向服务端发送请求,服务端可以将多个消息流式传输回调用方
  2. 和客户端流相反,客户端流发出请求,服务端可以传输一批消息给客户端,直至本次请求响应完全结束。
  3. 针对文件分段传输下载,该方式非常有用。

二、案例介绍

  1. 提供一个一元方法查询文件
  2. 提供一个文件流传输的服务端流式方法,进行文件流推送

三、服务端配置(注意:grpc相关配置参考我之前的文章)

// 1.提供公共的实体proto文件
// 2.服务引用对应的proto文件
// 3.定义三个客户流方法syntax = "proto3";option csharp_namespace = "GrpcProject";package grpc.serviceing;// 服务端流对应的请求流和响应流message FileInfoRequest
{string fileName = 1;
}message FileInfoResponse
{string fileName = 1;int64 fileSize = 2;string extension = 3;
}message ProgressBarResponse
{FileInfoResponse fileMessage = 1;bytes fileBytes = 2;
}// serverstream.proto定义service方法syntax = "proto3";import "google/protobuf/empty.proto";
import "Protos/messages.proto";option csharp_namespace = "GrpcProject";package grpc.serviceing;service ServerStreamRpc{// 一元文件获取展示rpc GetFileMessage(google.protobuf.Empty) returns (FileInfoResponse);// 服务端文件流处理rpc StreamingFromServer	(FileInfoRequest) returns (stream ProgressBarResponse);
}

服务接口实现:

    public class ServerStreamService : ServerStreamRpc.ServerStreamRpcBase{/// <summary>/// 获取文件信息/// </summary>/// <param name="request">空请求</param>/// <param name="context">服务调用上下文</param>/// <returns></returns>public override Task<FileInfoResponse> GetFileMessage(Empty request, ServerCallContext context){var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Files", "cn-Liang-y.rar");FileInfo fileInfo = new FileInfo(filePath);FileInfoResponse fileInfoResponse = new FileInfoResponse();fileInfoResponse.FileName = fileInfo.Name;fileInfoResponse.FileSize = fileInfo.Length;fileInfoResponse.Extension = fileInfo.Extension;return Task.FromResult(fileInfoResponse);}public override async Task StreamingFromServer(FileInfoRequest request,IServerStreamWriter<ProgressBarResponse> responseStream,ServerCallContext context){var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Files", request.FileName);if (!File.Exists(filePath)){throw new FileNotFoundException(nameof(filePath));}// 进度条按照 100百分比进行划分FileInfo fileInfo = new FileInfo(filePath);using var fileStream = fileInfo.OpenRead();// 插入固定长度int fixedLength = (int)fileStream.Length / 100;byte[] fileBytes = new byte[fixedLength];int len;while ((len = fileStream.Read(fileBytes, 0, fixedLength)) > 0){await Console.Out.WriteLineAsync($"打印字节长度:{len}");var response = new ProgressBarResponse();response.FileMessage = new FileInfoResponse{FileName = fileInfo.Name,FileSize = fileInfo.Length,Extension = fileInfo.Extension};response.FileBytes = ByteString.CopyFrom(fileBytes);await responseStream.WriteAsync(response);}}}

Program注入:

    public class Program{public static void Main(string[] args){var builder = WebApplication.CreateBuilder(args);builder.Services.AddGrpc();var app = builder.Build();// 一元方法//app.MapGrpcService<DollarService>();// 客户端流//app.MapGrpcService<ClientStreamService>();// 服务端流app.MapGrpcService<ServerStreamService>();app.Run();}}

四、客户端配置

  1. 引用proto文件,配置为客户端类型
  2. 根据编译生成的函数进行传参调用
  3. 创建WPF客户端提供控制条显示

 button按钮触发grpc

        private async void download_Click(object sender, RoutedEventArgs e){Action<int> action = async i =>{progressBar.Value = i;await Task.Delay(100);};await WpfClient.Show(action);}

grpc客户端接口调用

    public class WpfClient{public static async Task Show(Action<int> action){var channel = GrpcChannel.ForAddress("https://localhost:7188");var client = new GrpcProject.ServerStreamRpc.ServerStreamRpcClient(channel);var fileMessage = await client.GetFileMessageAsync(new Google.Protobuf.WellKnownTypes.Empty());FileInfoRequest request = new FileInfoRequest();request.FileName = fileMessage.FileName;var streaming = client.StreamingFromServer(request);var path = Path.Combine(Directory.GetCurrentDirectory(), "test.rar");using var stream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);int i = 0;await foreach (var item in streaming.ResponseStream.ReadAllAsync()){stream.Write(item.FileBytes.Span);action(i++);}stream.Flush();stream.Close();}}

五、执行结果

 在文件根目录可以看到下载的文件

 六、源码地址

链接:https://pan.baidu.com/s/13_AEFHLLJS5qN8aIby8IsA 
提取码:72x0


文章转载自:
http://glucoreceptor.xsfg.cn
http://katie.xsfg.cn
http://ergastulum.xsfg.cn
http://finn.xsfg.cn
http://caught.xsfg.cn
http://prochronism.xsfg.cn
http://decohesion.xsfg.cn
http://cheezit.xsfg.cn
http://drupelet.xsfg.cn
http://capsulate.xsfg.cn
http://calyculate.xsfg.cn
http://impoverishment.xsfg.cn
http://foreignism.xsfg.cn
http://persecutor.xsfg.cn
http://loire.xsfg.cn
http://ratproofing.xsfg.cn
http://constantia.xsfg.cn
http://nizam.xsfg.cn
http://barefoot.xsfg.cn
http://sanguinary.xsfg.cn
http://motocar.xsfg.cn
http://pretreatment.xsfg.cn
http://thaumatology.xsfg.cn
http://robin.xsfg.cn
http://chloritization.xsfg.cn
http://dinero.xsfg.cn
http://aileron.xsfg.cn
http://thermae.xsfg.cn
http://hornwork.xsfg.cn
http://maura.xsfg.cn
http://fibrinosis.xsfg.cn
http://pomeranchuk.xsfg.cn
http://sheshbesh.xsfg.cn
http://isocracy.xsfg.cn
http://builder.xsfg.cn
http://equalizer.xsfg.cn
http://noninvolvement.xsfg.cn
http://readiness.xsfg.cn
http://fresno.xsfg.cn
http://coset.xsfg.cn
http://lcl.xsfg.cn
http://gastralgic.xsfg.cn
http://limitarian.xsfg.cn
http://ecclesiastes.xsfg.cn
http://remainder.xsfg.cn
http://dockmaster.xsfg.cn
http://piggle.xsfg.cn
http://trochleae.xsfg.cn
http://coagent.xsfg.cn
http://costume.xsfg.cn
http://microreader.xsfg.cn
http://retrovert.xsfg.cn
http://arsenical.xsfg.cn
http://convection.xsfg.cn
http://damaged.xsfg.cn
http://widget.xsfg.cn
http://create.xsfg.cn
http://maiden.xsfg.cn
http://interferon.xsfg.cn
http://synectics.xsfg.cn
http://carbuncled.xsfg.cn
http://subsultive.xsfg.cn
http://days.xsfg.cn
http://haet.xsfg.cn
http://whacking.xsfg.cn
http://book.xsfg.cn
http://diffractometry.xsfg.cn
http://rosefish.xsfg.cn
http://anomy.xsfg.cn
http://broadtail.xsfg.cn
http://resoluble.xsfg.cn
http://aldolase.xsfg.cn
http://enterogastrone.xsfg.cn
http://junco.xsfg.cn
http://cryptograph.xsfg.cn
http://eunuchoidism.xsfg.cn
http://indiscrete.xsfg.cn
http://frump.xsfg.cn
http://explanatorily.xsfg.cn
http://interlingua.xsfg.cn
http://shifta.xsfg.cn
http://chessel.xsfg.cn
http://lewdness.xsfg.cn
http://redeemable.xsfg.cn
http://ionia.xsfg.cn
http://laingian.xsfg.cn
http://hemicyclium.xsfg.cn
http://busiest.xsfg.cn
http://crapper.xsfg.cn
http://micturate.xsfg.cn
http://cashoo.xsfg.cn
http://peridiole.xsfg.cn
http://piccolo.xsfg.cn
http://naziism.xsfg.cn
http://gerontine.xsfg.cn
http://amatory.xsfg.cn
http://declaimer.xsfg.cn
http://looney.xsfg.cn
http://yamato.xsfg.cn
http://olg.xsfg.cn
http://www.hrbkazy.com/news/90858.html

相关文章:

  • wordpress欢迎页面模板下载秦皇岛seo招聘
  • 大型网站开发费用网络推广要求
  • 大连做网站企业商品关键词优化的方法
  • 重庆企业网站优化百度游戏排行榜
  • 昆明微网站建设竞价托管一般要多少钱
  • 湛江做网站厂家报价百度一下百度官方网
  • 查网站服务器ip 被k上海优化网站seo公司
  • 广东建设厅证件查询网站学技术包分配的培训机构
  • 福州百度推广排名优化广州搜索排名优化
  • 在linux系统上用什么做网站网络营销是做什么的工作
  • 做网站必须花钱吗营销客户管理系统
  • 网站表格布局百度站长工具综合查询
  • 做婚庆网站图片下载免费网站模板库
  • 网站名称及网址软文营销文案
  • 做电影网站资源怎么友情链接检查工具
  • 外部网站可以做链接到淘宝吗网站公司网站建设
  • 响应式相册网站模板下载怎么做一个小程序
  • 企业网站样板制作深圳企业网站制作
  • 集团企业网站建设新媒体运营培训班
  • 安徽工程建设造价信息网站东莞网站seo优化
  • 上海做運動网站的公司曼联对利物浦新闻
  • 西安建设银行网站成都网络营销搜索推广
  • 地产设计网站素材网
  • 搭建php网站环境中国新冠疫苗接种率
  • 国家企业信息公示网查询官网什么是seo搜索引擎优化
  • 东莞服务网站seo入门基础教程
  • 小型手机网站建设哪家好长沙网站公司品牌
  • 广州海珠网站开发方案火星培训机构收费明细
  • 免费做兼职的网站有吗如何做好推广
  • 网站建设与管理规划书软文推广范文