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

国内男女直接做的视频网站找个免费网站这么难吗

国内男女直接做的视频网站,找个免费网站这么难吗,上海高端网站定,西安响应式网站开发4种通信模式 1、简单模式(Simple RPC) 简单模式:也称简单 RPC,即客户端发起一次请求,服务端响应处理后返回一个结果给客户端。 在 proto 文件中可如下定义: rpc SayHello(HelloRequest) returns (Hello…

4种通信模式

1、简单模式(Simple RPC)

简单模式:也称简单 RPC,即客户端发起一次请求,服务端响应处理后返回一个结果给客户端。

在 proto 文件中可如下定义:

rpc SayHello(HelloRequest) returns (HelloResponse);
2、服务端数据流模式(Server-side streaming RPC)

服务端数据流模式:也称服务端流式 RPC,即客户端发起一次请求,服务端可以连续返回数据流。
比如:客户端向服务端发送了一个查询数据库的请求,服务端持续返回多次结果。(即客户端发送一次请求,服务端查询到数据库有一万条数据,服务端分批返回10次,每次返回1000条数据给客户端)。

在 proto 文件中可如下定义:

rpc LotsOfReplies(HelloRequest) returns (stream HelloResponse);

注意:在返回值前面加了stream

3、客户端数据流模式(Client-side streaming RPC)

客户端数据流模式:也称客户端流式 RPC,与服务端数据流模式相反,客户端持续向服务端发送数据流,在发送结束后,由服务端返回一个响应。
比如:客户端有一万条数据 ,分批多次请求服务端,服务端接收后把这些数据都存到数据库,然后返回一次结果给客户端。

在 proto 文件中可如下定义:

rpc LotsOfGreetings(stream HelloRequest) returns (HelloResponse);

注意:在参数前面加了stream

4、双向数据流模式(Bidirectional streaming RPC)

双向数据流模式:也称双向流式 RPC,即客户端和服务端都可以向对方多次收发数据。

比如:客户端有一万条数据 ,分批多次请求服务端,服务端每次接收后存到数据库后都发送一次结果给客户端。

在 proto 文件中可如下定义:

rpc BidiHello(stream HelloRequest) returns (stream HelloResponse);

注意:参数和返回前面都加了stream

代码示例

1、简单模式

product.proto

syntax = "proto3";option java_multiple_files = true;
option java_package = "com.github.xjs.grpcapi";
option java_outer_classname = "ProductProto";package product;service ProductInfo {rpc addProduct (Product) returns (ProductId);rpc getProduct(ProductId) returns(Product);
}message Product {string id = 1;string name=2;string description=3;float price=4;
}message ProductId {string value = 1;
}

客户端:

public static void main(String[] args) {ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 50050).usePlaintext().build();ProductInfoGrpc.ProductInfoBlockingStub stub = ProductInfoGrpc.newBlockingStub(channel);Product p = Product.newBuilder().setId("1").setPrice(100).setName("21天精通Java").setDescription("21天精通Java").build();ProductId productId = stub.addProduct(p);System.out.println("productId.getValue() = " + productId.getValue());Product product = stub.getProduct(ProductId.newBuilder().setValue("99999").build());System.out.println("product.getName() = " + product.getName());channel.shutdown();
}

服务端:

public class ProductInfoImpl extends ProductInfoGrpc.ProductInfoImplBase {@Overridepublic void addProduct(Product request, StreamObserver<ProductId> responseObserver) {// System.out.println("request.toString() = " + request.toString());System.out.println(TextFormat.printer().escapingNonAscii(false).printToString(request));ProductId productId = ProductId.newBuilder().setValue(request.getId()).build();responseObserver.onNext(productId);responseObserver.onCompleted();}@Overridepublic void getProduct(ProductId request, StreamObserver<Product> responseObserver) {System.out.println(TextFormat.printer().escapingNonAscii(false).printToString(request));Product product = Product.newBuilder().setId(request.getValue()).setName("三国演义").build();responseObserver.onNext(product);responseObserver.onCompleted();}
}
2、服务端数据流模式(Server-side streaming RPC)

product.proto

syntax = "proto3";option java_multiple_files = true;
option java_package = "com.github.xjs.grpcapi.clientstream";
option java_outer_classname = "ProductProto";package product.clientstream;service ProductInfo {rpc getProductBatch (ProductGetBatchRequest) returns (stream Product);
}message ProductGetBatchRequest {int32 count = 10;}message Product {string id = 1;string name=2;string description=3;float price=4;
}

客户端:

public static void main(String[] args) throws Exception {CountDownLatch countDownLatch = new CountDownLatch(1);ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 50050).usePlaintext().build();ProductInfoGrpc.ProductInfoStub stub = ProductInfoGrpc.newStub(channel);// 等待接收服务端的响应StreamObserver<Product> responseObserver = new StreamObserver<Product>() {@Overridepublic void onNext(Product result) {System.out.println("服务端返回:" + result.toString());}@Overridepublic void onError(Throwable throwable) {throwable.printStackTrace();}@Overridepublic void onCompleted() {System.out.println("服务端响应完成");// 关闭channelchannel.shutdown();// 结束程序countDownLatch.countDown();}};ProductGetBatchRequest request = ProductGetBatchRequest.newBuilder().setCount(10).build();stub.getProductBatch(request, responseObserver);// 等待结束countDownLatch.await();}

服务端:

@Override
public void getProductBatch(ProductGetBatchRequest request, StreamObserver<Product> responseObserver) {int count = request.getCount();for(int i=0; i<count; i++){Product product = Product.newBuilder().setId(""+(1+1)).setName("product" + i) .setPrice(100+i).build();responseObserver.onNext(product);System.out.println("发送数据:" + product);}responseObserver.onCompleted();System.out.println("发送完成");
}
3、客户端数据流模式(Client-side streaming RPC)

product.proto

syntax = "proto3";option java_multiple_files = true;
option java_package = "com.github.xjs.grpcapi.clientstream";
option java_outer_classname = "ProductProto";package product.clientstream;service ProductInfo {rpc addProductBatch (stream Product) returns (ProductAddResult);
}message Product {string id = 1;string name=2;string description=3;float price=4;
}message ProductAddResult {int32 count = 1;
}

客户端:

public static void main(String[] args) throws Exception {CountDownLatch countDownLatch = new CountDownLatch(1);ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 50050).usePlaintext().build();ProductInfoGrpc.ProductInfoStub stub = ProductInfoGrpc.newStub(channel);// 等待接收服务端的响应StreamObserver<ProductAddResult> responseObserver = new StreamObserver<ProductAddResult>() {@Overridepublic void onNext(ProductAddResult result) {System.out.println("服务端返回:" + result.toString());}@Overridepublic void onError(Throwable throwable) {throwable.printStackTrace();}@Overridepublic void onCompleted() {System.out.println("服务端响应完成");// 关闭channelchannel.shutdown();// 结束程序countDownLatch.countDown();}};StreamObserver<Product> requestObserver = stub.addProductBatch(responseObserver);for(int i=0;i<10;i++){Product p = Product.newBuilder().setId("" + (i+1)).setPrice(100).setName("21天精通Java").setDescription("21天精通Java").build();requestObserver.onNext(p);}requestObserver.onCompleted();// 等待结束countDownLatch.await();
}

服务端:

public io.grpc.stub.StreamObserver<Product> addProductBatch(io.grpc.stub.StreamObserver<ProductAddResult> responseObserver) {return new StreamObserver<Product>() {List<Product> products = new ArrayList<>();@Overridepublic void onNext(Product product) {// 接收客户端请求System.out.println(TextFormat.printer().escapingNonAscii(false).printToString(product));products.add(product);}@Overridepublic void onError(Throwable throwable) {// 错误处理throwable.printStackTrace();}@Overridepublic void onCompleted() {// 客户端请求结束,发送响应ProductAddResult result = ProductAddResult.newBuilder().setCount(products.size()).build();responseObserver.onNext(result);responseObserver.onCompleted();System.out.println("服务端响应结束");}};
}
4、双向数据流模式(Bidirectional streaming RPC)

product.proto

syntax = "proto3";option java_multiple_files = true;
option java_package = "com.github.xjs.grpcapi.bidirectionalstream";
option java_outer_classname = "ProductProto";package product.clientstream;service ProductInfo {rpc saveProductBatch (stream Product) returns (stream ProductSaveResult);
}message ProductSaveResult {bool success = 1;
}message Product {string id = 1;string name=2;string description=3;float price=4;
}

客户端:

public static void main(String[] args) throws Exception {CountDownLatch countDownLatch = new CountDownLatch(1);ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 50050).usePlaintext().build();ProductInfoGrpc.ProductInfoStub stub = ProductInfoGrpc.newStub(channel);// 等待接收服务端的响应StreamObserver<ProductSaveResult> responseObserver = new StreamObserver<ProductSaveResult>() {@Overridepublic void onNext(ProductSaveResult result) {System.out.println("服务端返回:" + result.toString());}@Overridepublic void onError(Throwable throwable) {throwable.printStackTrace();}@Overridepublic void onCompleted() {System.out.println("服务端响应完成");// 关闭channelchannel.shutdown();// 结束程序countDownLatch.countDown();}};StreamObserver<Product> requestObserver = stub.saveProductBatch(responseObserver);for(int i=0; i<10; i++){Product p = Product.newBuilder().setId(""+(i+1)).setName("product"+i).setPrice(100+i).build();requestObserver.onNext(p);System.out.println("客户端发送:" + p.toString());}requestObserver.onCompleted();System.out.println("客户端发送完成");// 等待结束countDownLatch.await();
}

服务端:

@Override
public StreamObserver<Product> saveProductBatch(StreamObserver<ProductSaveResult> responseObserver) {return new StreamObserver<Product>() {@Overridepublic void onNext(Product product) {System.out.println("收到客户端请求:" + product);ProductSaveResult result = ProductSaveResult.newBuilder().setSuccess(true).build();System.out.println("发送响应");responseObserver.onNext(result);}@Overridepublic void onError(Throwable throwable) {throwable.printStackTrace();}@Overridepublic void onCompleted() {System.out.println("客户端请求完成");responseObserver.onCompleted();System.out.println("服务端响应完成");}};
}

完成的源码下载:https://github.com/xjs1919/learning-demo/tree/master/grpc-demo


文章转载自:
http://sailor.ybmp.cn
http://uvulitis.ybmp.cn
http://qualmish.ybmp.cn
http://spuriously.ybmp.cn
http://interoperable.ybmp.cn
http://beeper.ybmp.cn
http://bodily.ybmp.cn
http://ulster.ybmp.cn
http://snuffling.ybmp.cn
http://localite.ybmp.cn
http://pelt.ybmp.cn
http://marking.ybmp.cn
http://nouadhibou.ybmp.cn
http://lacunosis.ybmp.cn
http://entameba.ybmp.cn
http://peru.ybmp.cn
http://telegnosis.ybmp.cn
http://keener.ybmp.cn
http://granddaughter.ybmp.cn
http://colic.ybmp.cn
http://frolicky.ybmp.cn
http://shahaptian.ybmp.cn
http://vycor.ybmp.cn
http://curvesome.ybmp.cn
http://prevalence.ybmp.cn
http://choochoo.ybmp.cn
http://ectomorph.ybmp.cn
http://unclubbable.ybmp.cn
http://renovation.ybmp.cn
http://freedom.ybmp.cn
http://sandpit.ybmp.cn
http://epiphloedal.ybmp.cn
http://varley.ybmp.cn
http://outpensioner.ybmp.cn
http://shadowboxing.ybmp.cn
http://machinate.ybmp.cn
http://psalterion.ybmp.cn
http://histographer.ybmp.cn
http://thor.ybmp.cn
http://average.ybmp.cn
http://upstreet.ybmp.cn
http://bark.ybmp.cn
http://rhymeless.ybmp.cn
http://ephebus.ybmp.cn
http://manak.ybmp.cn
http://camembert.ybmp.cn
http://sandiness.ybmp.cn
http://bolshevist.ybmp.cn
http://ghana.ybmp.cn
http://mastercard.ybmp.cn
http://socius.ybmp.cn
http://offend.ybmp.cn
http://delible.ybmp.cn
http://forspent.ybmp.cn
http://nurse.ybmp.cn
http://continental.ybmp.cn
http://stingy.ybmp.cn
http://november.ybmp.cn
http://wiredrawn.ybmp.cn
http://septipartite.ybmp.cn
http://dejeuner.ybmp.cn
http://boon.ybmp.cn
http://unbundling.ybmp.cn
http://unci.ybmp.cn
http://manus.ybmp.cn
http://outpension.ybmp.cn
http://lavement.ybmp.cn
http://floe.ybmp.cn
http://isolated.ybmp.cn
http://examine.ybmp.cn
http://druidism.ybmp.cn
http://disruption.ybmp.cn
http://cystinuria.ybmp.cn
http://ophthalmologist.ybmp.cn
http://adit.ybmp.cn
http://euphemism.ybmp.cn
http://intensely.ybmp.cn
http://deceleron.ybmp.cn
http://irretentive.ybmp.cn
http://pyrethrum.ybmp.cn
http://lustful.ybmp.cn
http://biopotency.ybmp.cn
http://expire.ybmp.cn
http://cottonmouth.ybmp.cn
http://suburbanity.ybmp.cn
http://deducible.ybmp.cn
http://insurmountability.ybmp.cn
http://bashaw.ybmp.cn
http://lifeward.ybmp.cn
http://conchologist.ybmp.cn
http://indulgence.ybmp.cn
http://bamboozle.ybmp.cn
http://snuffers.ybmp.cn
http://conquian.ybmp.cn
http://heating.ybmp.cn
http://trimorphous.ybmp.cn
http://ran.ybmp.cn
http://sandwort.ybmp.cn
http://mispickel.ybmp.cn
http://engarb.ybmp.cn
http://www.15wanjia.com/news/94668.html

相关文章:

  • html php网站开发报告各种推广平台
  • dnf免做卡领取网站seo技术外包公司
  • 做网站手机端不做PC可以吗seo标签怎么优化
  • 太原经济型网站建设价格域名注册 阿里云
  • 做的网站怎样适配手机想要导航推广网页怎么做
  • 个人做的微网站一年要交多少钱武汉seo网站管理
  • 专业网站优化seoseo系统源码出售
  • 外贸网站如何做seo百度手机应用商店
  • 电子科技网站模板广州营销课程培训班
  • wordpress mycred汉化惠州百度seo
  • 国家建设厅官方网站seo免费优化工具
  • wordpress开源系统aso优化吧
  • 服装厂做1688网站效果好不好模板网站哪个好
  • 企业网站的基本功能有哪些html网页制作app
  • 免费字体设计网站百度电话客服24小时
  • 企业为什么做网站系统网站seo基础
  • 做网站最好的语言网络广告的优势有哪些
  • 滨海住房和城乡建设局网站手机导航下载2022新版
  • 网站域名hk今日新闻大事件
  • 做资料网站是自己建服务器好还是租用好网络宣传推广方案
  • 网站如何取消验证码职业培训学校加盟
  • 织梦网站地图在线生成广告公司业务推广
  • 哪些网站才能具备完整的八项网络营销功能灰色词优化培训
  • 珠海企业建站广东短视频seo搜索哪家好
  • 网站关键字优化公司舆情分析网站
  • 学做婴儿衣服网站挖掘爱站网
  • 做特产的网站开张怎么宣传百度竞价推广的技巧
  • 网站建设中页面html网络销售面试问题有哪些
  • php 免费网站空间申请宁波网络推广运营公司电话
  • 装修公司做自己网站怎么快速优化关键词排名