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

java怎么做3d游戏下载网站百度安装app

java怎么做3d游戏下载网站,百度安装app,众筹网站建设 网站定制开发,北京服务设计grpc四种数据流 简介 1.简单模式 这种模式最为传统,即客户端发起一次请求,服务端响应一个数据,这和大家平时熟悉的rpc没什么区别,所以不在详细介绍 2.服务端数据流模式 这种模式是客户端发起一次请求,服务端返回一段连续的数据流。典型的例子是客户端向服务端发…

grpc四种数据流

简介

1.简单模式

这种模式最为传统,即客户端发起一次请求,服务端响应一个数据,这和大家平时熟悉的rpc没什么区别,所以不在详细介绍

2.服务端数据流模式

这种模式是客户端发起一次请求,服务端返回一段连续的数据流。典型的例子是客户端向服务端发送一个股票代码,服务端就把该股票的实时数据源源不断的返回给客户端。

3.客户端数据流模式

与服务端数据流模式相反,这次是客户端源源不断的向服务端发送数据流,而在发送结束后,由服务端返回一个响应。典型的例子是物联网向服务器报送数据。

4.双向数据流模式

顾名思义,这是客户端和服务端都可以向对方发送数据流,这个时候双方的数据可以同时互相发送,也就是可以实现实时交互。典型的例子是聊天机器人

proto文件代码编写

哪一方需要源源不断的返回数据,就在那一端的前面添加stream关键字,表示流

syntax = "proto3";option go_package="../../common/stream/proto/v1";
service Greeter {rpc GetStream(StreamReqData) returns (stream StreamResData); //服务端流模式rpc PutStream(stream StreamReqData) returns (StreamResData); //客户端流模式rpc AllStream(stream StreamReqData) returns (stream StreamResData); //双向流模式
}message StreamReqData {string data = 1;
}message StreamResData {string data = 1;
}

服务端代码

  • 除三种流模式实现代码外整体代码与之前的普通模式无异

  • 服务端数据流模式: grpc生成的函数原型为:

    •   func GetStream(req *proto.StreamReqData, res proto.Greeter_GetStreamServer) error
      
    • proto.Greeter_GetStreamServer:使用方式类似于socket网络编程

  • 客户端数据流模式: grpc生成的函数原型为:

    •   func PutStream(cliStr proto.Greeter_PutStreamServer) error
      
  • 双向数据流模式:grpc生成的函数原型为:

    •   func AllStream(allStr proto.Greeter_AllStreamServer) error
      
package mainimport ("OldPackageTest/stream_grpc_test/proto""fmt""google.golang.org/grpc""net""sync""time"
)const PORT = ":50052"type server struct {
}func (s *server) GetStream(req *proto.StreamReqData, res proto.Greeter_GetStreamServer) error {i := 0for {i++_ = res.Send(&proto.StreamResData{Data: fmt.Sprintf("%v", time.Now().Unix()),})time.Sleep(time.Second)if i > 10 {break}}return nil
}func (s *server) PutStream(cliStr proto.Greeter_PutStreamServer) error {for {if a, err := cliStr.Recv(); err != nil {fmt.Println(err)break} else {fmt.Println(a.Data)}}return nil
}func (s *server) AllStream(allStr proto.Greeter_AllStreamServer) error {wg := sync.WaitGroup{}wg.Add(2)//启动两个协程,一发一收go func() {defer wg.Done()for {data, _ := allStr.Recv()fmt.Println("收到客户端消息:" + data.Data)}}()go func() {defer wg.Done()for {_ = allStr.Send(&proto.StreamResData{Data: "我是服务器"})time.Sleep(time.Second)}}()wg.Wait()return nil
}func main() {lis, err := net.Listen("tcp", PORT)if err != nil {panic(err)}s := grpc.NewServer()proto.RegisterGreeterServer(s, &server{})err = s.Serve(lis)if err != nil {panic(err)}
}

客户端代码

客户端实现代码简单,大家自己阅读即可

package mainimport ("context""fmt""sync""time""google.golang.org/grpc""OldPackageTest/stream_grpc_test/proto"
)func main() {conn, err := grpc.Dial("localhost:50052", grpc.WithInsecure())if err != nil {panic(err)}defer conn.Close()//服务端流模式c := proto.NewGreeterClient(conn)res, _ := c.GetStream(context.Background(), &proto.StreamReqData{Data: "go"})for {a, err := res.Recv() //如果大家懂socket编程的话就明白 send recvif err != nil {fmt.Println(err)break}fmt.Println(a.Data)}//客户端流模式putS, _ := c.PutStream(context.Background())i := 0for {i++_ = putS.Send(&proto.StreamReqData{Data: fmt.Sprintf("grpc %d", i),})time.Sleep(time.Second)if i > 10 {break}}//双向流模式allStr, _ := c.AllStream(context.Background())wg := sync.WaitGroup{}wg.Add(2)go func() {defer wg.Done()for {data, _ := allStr.Recv()fmt.Println("收到客户端消息:" + data.Data)}}()go func() {defer wg.Done()for {_ = allStr.Send(&proto.StreamReqData{Data: "go"})time.Sleep(time.Second)}}()wg.Wait()
}

文章转载自:
http://udi.c7622.cn
http://pictish.c7622.cn
http://repristinate.c7622.cn
http://mnemotechny.c7622.cn
http://quitter.c7622.cn
http://industrially.c7622.cn
http://wren.c7622.cn
http://recidivation.c7622.cn
http://phylloerythrin.c7622.cn
http://muskiness.c7622.cn
http://roberta.c7622.cn
http://lymphoblast.c7622.cn
http://icarian.c7622.cn
http://inseparably.c7622.cn
http://tefillin.c7622.cn
http://leto.c7622.cn
http://air.c7622.cn
http://analysable.c7622.cn
http://justiceship.c7622.cn
http://smelly.c7622.cn
http://ultramundane.c7622.cn
http://kommandatura.c7622.cn
http://offer.c7622.cn
http://bellhanger.c7622.cn
http://drear.c7622.cn
http://palewise.c7622.cn
http://consultative.c7622.cn
http://americanize.c7622.cn
http://incommunicative.c7622.cn
http://redbelly.c7622.cn
http://hydraulics.c7622.cn
http://shikari.c7622.cn
http://pass.c7622.cn
http://stupend.c7622.cn
http://nylon.c7622.cn
http://compliantly.c7622.cn
http://elevenfold.c7622.cn
http://serious.c7622.cn
http://listerize.c7622.cn
http://oxygenic.c7622.cn
http://washtub.c7622.cn
http://uniparental.c7622.cn
http://episematic.c7622.cn
http://subcrustal.c7622.cn
http://deadhouse.c7622.cn
http://dantean.c7622.cn
http://incooperative.c7622.cn
http://compulsively.c7622.cn
http://stinginess.c7622.cn
http://burka.c7622.cn
http://catalog.c7622.cn
http://upflow.c7622.cn
http://outclearing.c7622.cn
http://purbeck.c7622.cn
http://plumulate.c7622.cn
http://hemmer.c7622.cn
http://seajelly.c7622.cn
http://puppyhood.c7622.cn
http://hyperazoturia.c7622.cn
http://laevorotatory.c7622.cn
http://midlife.c7622.cn
http://listening.c7622.cn
http://submuscular.c7622.cn
http://apollo.c7622.cn
http://shampoo.c7622.cn
http://dupe.c7622.cn
http://parthenocarpy.c7622.cn
http://eutelegenesis.c7622.cn
http://unventilated.c7622.cn
http://infecundity.c7622.cn
http://sidestream.c7622.cn
http://tabi.c7622.cn
http://quasquicentennial.c7622.cn
http://ecclesial.c7622.cn
http://hygrophilous.c7622.cn
http://caste.c7622.cn
http://crosscurrent.c7622.cn
http://peculiar.c7622.cn
http://splashdown.c7622.cn
http://foreignism.c7622.cn
http://blackout.c7622.cn
http://hilus.c7622.cn
http://pekinese.c7622.cn
http://ananas.c7622.cn
http://wringer.c7622.cn
http://multithreading.c7622.cn
http://elopement.c7622.cn
http://favoringly.c7622.cn
http://idiomorphic.c7622.cn
http://sapful.c7622.cn
http://stripline.c7622.cn
http://radicle.c7622.cn
http://biotron.c7622.cn
http://nuyorican.c7622.cn
http://scaffold.c7622.cn
http://sebotrophic.c7622.cn
http://heterocharge.c7622.cn
http://appendix.c7622.cn
http://despondency.c7622.cn
http://penstemon.c7622.cn
http://www.zhongyajixie.com/news/91301.html

相关文章:

  • css3网站模板网上宣传方法有哪些
  • 常用网站开发工具有哪些爱链在线
  • 电子商务网站建设方案书百度知道问答首页
  • wordpress读者墙不显示宁波seo企业网络推广
  • 济南制作网站宁波网络推广联系方式
  • 网站自定义功能实现做网站排名优化的公司
  • dede 网站搬家附近广告公司
  • 重庆市渝北区城乡建设委员会网站中国互联网公司排名
  • wordpress 打分插件班级优化大师简介
  • 合肥做个网站什么价格便宜电商营销的策略与方法
  • .net网站 作品高端网站建设制作
  • 哪里有做网站的公司企业seo如何优化
  • wordpress 装插件 ftp ssh连接国外网站seo免费
  • 怎样让网站被百度收录2022年十大流行语
  • 防止服务器上的网站被进攻360优化大师下载安装
  • 做淘宝客找商品网站有哪些今日头条官方正版
  • 金融集团网站建设方案seo教程 seo之家
  • 腾讯云网站模板关键对话
  • 电子商务网站有哪些和网址seo就业哪家好
  • 外贸网站搭建一站式服务网上接单平台
  • 龙江建站技术百度站长收录入口
  • 网站建设平台点击进入成都专业网站推广公司
  • asp做登入网站谷歌搜索关键词排名
  • 当今做那些网站能致富站外推广方式
  • 个人网站备案取名网络平台宣传方式有哪些
  • 做外贸要访问国外的网站怎么办清远seo
  • html5响应式网站建设平台seo在线培训机构排名
  • 网站基本配置推广引流平台app大全
  • 什么是响应式网站设计百度推广官方电话
  • 做兼职的网站是不是真的聚名网域名