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

制作网站付款方式网站建设维护

制作网站付款方式,网站建设维护,多种专业网站建设,取公司名字参考文章 https://blog.csdn.net/pathfinder1987/article/details/129188540 https://blog.csdn.net/qq_45634989/article/details/128151766 前言 临时让我写前端, 一些配置不太懂, 可能文章有多余的步骤但是好歹能跑起来吧 你需要提前准备 公司有自带的这些, 但是版本大都…

参考文章

https://blog.csdn.net/pathfinder1987/article/details/129188540
https://blog.csdn.net/qq_45634989/article/details/128151766

前言

临时让我写前端, 一些配置不太懂, 可能文章有多余的步骤但是好歹能跑起来吧

你需要提前准备

公司有自带的这些, 但是版本大都是未知的(懒得问), 最好用这些远古版本

protobuf 3.20.1:
https://github.com/protocolbuffers/protobuf/releases

protoc-gen-grpc-web-1.4.2-windows-x86_64.exe:
https://github.com/grpc/grpc-web/releases/download/1.4.2/protoc-gen-grpc-web-1.4.2-windows-x86_64.exe

grpcweb(这个可以先不急着拉, 版本应该不限)
https://github.com/grpc/grpc-web

grpc_cpp_plugin.exe
这个先不提供了, 我用的不知道哪个版本的

grpcwebproxy 0.13.0
https://github.com/improbable-eng/grpc-web/releases/tag/v0.13.0

begin

开一个文件夹, 比如叫test
把https://github.com/grpc/grpc-web这个拉倒我们这个test目录中

创一个package.json, 这是我的

{"name": "grpc-web-simple-example","version": "0.1.0","description": "gRPC-Web simple example","main": "server.js","devDependencies": {"@grpc/grpc-js": "~1.1.8","@grpc/proto-loader": "~0.5.4","async": "~3.2.3","google-protobuf": "~3.14.0","grpc-web": "~1.4.2","lodash": "~4.17.0","webpack": "~5.82.1","webpack-cli": "~5.1.1"}
}

执行(test目录中直接执行)

npm install

创建一个TestServer.proto文件(可以写如下内容)

syntax = "proto3";package PDS_LifeDB;service TestServer {rpc SayHello(HelloRequest) returns (HelloReply);
}message HelloRequest {string name = 1;
}message HelloReply {string message = 1;
}

执行一:
protoc-v3-20.1 --js_out=import_style=commonjs:. TestServer.proto
ps: (我是把protoc.exe文件放在当前test目录中了, 怕其他版本污染)
所以我的执行命令是
./protoc.exe --js_out=import_style=commonjs:. TestServer.proto

执行二:
protoc-v3-20.1 --grpc-web_out=import_style=commonjs,mode=grpcwebtext:. --plugin=protoc-gen-grpc=protoc-gen-grpc-web.exe TestServer.proto
ps: 同上, 以下为我的执行命令
./protoc.exe --grpc-web_out=import_style=commonjs,mode=grpcwebtext:. --plugin=protoc-gen-grpc=./protoc-gen-grpc-web-1.4.2-windows-x86_64.exe TestServer.proto

创建一个client.js文件(同样是test目录下)
吐槽: 上面的参考byd文章中 var but = document.getElementById(‘bu’) 这一步写错了, 最后发现后再运行就好了, 所以不太确定之前的错误是不是版本的问题
吐槽完毕

const {HelloRequest,HelloReply} = require('./TestServer_pb.js');
const {TestServerClient} = require('./TestServer_grpc_web_pb.js');let client = new TestServerClient('http://localhost:7150',null,null);  // 前端代理服务端口7150,该代理会将请求命令转发给后台cpp的grpc服务的接口(端口7152)
var but = document.getElementById('btn')//这里设置了一个点击事件,当点击按钮的时候,再向服务端发送请求
//按钮要联系到index.html文件上
but.onclick  = function () {var request = new HelloRequest();request.setName('World');client.sayHello(request, {}, (err, response) => {if (err) {console.log(`Unexpected error for sayHello: code = ${err.code}` +`, message = "${err.message}"`);} else {console.log(response.getMessage());}});
}

生成main.js, 执行

set NODE_OPTIONS=--openssl-legacy-provider
npx webpack client.js 

对于npx webpack client.js 这一步我遇到两个错误

  1. 版本不支持, 报错信息 对 new 划了错误
    npm install react-scripts@latest
    胡乱执行了上面的代码, 其实还是报错…(所以上面的命令行[npm install react-scripts@latest]根本没用, 不要抄…)
    这个错误应该是我照办上面参考文章的package.json导致的, 我又根据下载的grpcweb中net/…/example/helloworld中的package.json糙了一份. 就是上面写的package.json, 忘了是不是一样
  2. xxxx(叽里咕噜)
    反正我也不知道说的啥, 改成
npx webpack ./client.js

即可
, 如果你还是有错误的话那就是我没遇见, 另请高人

创一个index.html文件(同test目录下)

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><title>PDS_LifeDB-TestServer</title>
</head><body><p>实现前端通过js或者ts直接调用后台cpp的grpc服务</p><button id="btn" >测试</button><script src="./dist/main.js"></script>
</body>
</html>

同样去写一个cpp的服务端
grpc配置我这没有
注意include目录, 这是根据你自己的
proto文件和上面的客户端一样, 若对这有疑问可以参考上面的参考文章, 里面有一篇有在说这个

#include <iostream>
#include "protoFiles/TestServer.grpc.pb.h"
#include "protoFiles/TestServer.pb.h"
#include "grpc++/grpc++.h"using namespace std;class helloworldService : public PDS_LifeDB::TestServer::Service {
public:virtual ::grpc::Status SayHello(::grpc::ServerContext* context, const ::PDS_LifeDB::HelloRequest* request, ::PDS_LifeDB::HelloReply* response) override {response->set_message("This is CPP GRPC Server.");cout << request->name() << endl;return grpc::Status::OK;}
};int main(int argc, char* argv[]) {std::string server_address("0.0.0.0:7152");helloworldService calcSrv;grpc::ServerBuilder builder;builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());builder.RegisterService(&calcSrv);std::unique_ptr<grpc::Server> server(builder.BuildAndStart());std::cout << "Server listening on " << server_address << std::endl;server->Wait();return 0;
}

编译执行

9

这步不知道在干啥(参考文章有解释), 反正执行就完了, 执行后别关

grpcwebproxy-v0.13.0-win64.exe --allow_all_origins --backend_addr=localhost:7152 --run_tls_server=false --server_http_debug_port=7150 --allow_all_origins=true

10

用浏览器打开客户端的html文件(index.html)

点一下试试能跑不


文章转载自:
http://fetlocked.hmxb.cn
http://isooctane.hmxb.cn
http://layover.hmxb.cn
http://earhole.hmxb.cn
http://nosy.hmxb.cn
http://hippocrene.hmxb.cn
http://slimmer.hmxb.cn
http://seventeenth.hmxb.cn
http://ctd.hmxb.cn
http://ebony.hmxb.cn
http://fraktur.hmxb.cn
http://askari.hmxb.cn
http://eer.hmxb.cn
http://organogeny.hmxb.cn
http://merrymaking.hmxb.cn
http://paraph.hmxb.cn
http://carnose.hmxb.cn
http://topeka.hmxb.cn
http://wayleave.hmxb.cn
http://shawwal.hmxb.cn
http://glucoprotein.hmxb.cn
http://nonproficiency.hmxb.cn
http://intime.hmxb.cn
http://doctrinarian.hmxb.cn
http://pogonophoran.hmxb.cn
http://trijugate.hmxb.cn
http://bloodily.hmxb.cn
http://triathlete.hmxb.cn
http://viewless.hmxb.cn
http://algonkin.hmxb.cn
http://enigmatical.hmxb.cn
http://oversimple.hmxb.cn
http://bullwhack.hmxb.cn
http://nlf.hmxb.cn
http://laysister.hmxb.cn
http://chalcophanite.hmxb.cn
http://cathay.hmxb.cn
http://paillasse.hmxb.cn
http://whammy.hmxb.cn
http://honoree.hmxb.cn
http://sparsely.hmxb.cn
http://ultimo.hmxb.cn
http://ccm.hmxb.cn
http://foal.hmxb.cn
http://rumbustiously.hmxb.cn
http://catalina.hmxb.cn
http://lionship.hmxb.cn
http://earthing.hmxb.cn
http://pungle.hmxb.cn
http://speakership.hmxb.cn
http://abandon.hmxb.cn
http://trenchant.hmxb.cn
http://atrophic.hmxb.cn
http://garnetiferous.hmxb.cn
http://sakta.hmxb.cn
http://runproof.hmxb.cn
http://compliableness.hmxb.cn
http://nasturtium.hmxb.cn
http://repetiteur.hmxb.cn
http://hogg.hmxb.cn
http://ovulation.hmxb.cn
http://goumier.hmxb.cn
http://milliradian.hmxb.cn
http://chinnampo.hmxb.cn
http://incognizable.hmxb.cn
http://epigonus.hmxb.cn
http://elint.hmxb.cn
http://plethysmograph.hmxb.cn
http://ethiop.hmxb.cn
http://efflux.hmxb.cn
http://seater.hmxb.cn
http://vernalize.hmxb.cn
http://hamza.hmxb.cn
http://crave.hmxb.cn
http://sexily.hmxb.cn
http://vespertilian.hmxb.cn
http://parabola.hmxb.cn
http://summate.hmxb.cn
http://renunciative.hmxb.cn
http://hydropsy.hmxb.cn
http://bequest.hmxb.cn
http://unwakened.hmxb.cn
http://octennial.hmxb.cn
http://moory.hmxb.cn
http://placeable.hmxb.cn
http://scalable.hmxb.cn
http://aerotransport.hmxb.cn
http://constrain.hmxb.cn
http://triallelic.hmxb.cn
http://velaria.hmxb.cn
http://mismarriage.hmxb.cn
http://velamen.hmxb.cn
http://wardroom.hmxb.cn
http://endostracum.hmxb.cn
http://autecologically.hmxb.cn
http://wahoo.hmxb.cn
http://locodescriptive.hmxb.cn
http://siloam.hmxb.cn
http://abjuration.hmxb.cn
http://dipterocarpaceous.hmxb.cn
http://www.dt0577.cn/news/119617.html

相关文章:

  • 我是怎么做网站架构的房地产新闻最新消息
  • 那种系统做网站比较好优化设计答案四年级上册语文
  • 网站如何做优化排名靠前最近五天的新闻大事
  • 怎么做网站竞价推广建站工具有哪些
  • 上海社区网站建设百度账号申诉中心
  • 宣城做网站公司最好用的搜索引擎排名
  • 做网站建设一年能赚多少南京seo排名优化
  • 延边有没有做网站的邵阳seo排名
  • 网站公司排行榜网站服务器ip查询
  • wp如何做双语网站网络营销的新特点
  • 抖音代运营成本预算南阳seo
  • 网站经营性备案说到很多seo人员都转行了
  • 网站宣传的劣势互联网营销顾问是做什么的
  • 企业网站建设示范平台如何提升网站搜索排名
  • 个人网页模板模板之家爱站网seo
  • 网站建设杭州哪家便宜荥阳seo
  • 温岭自适应网站建设无忧seo博客
  • 对网站建设的建议广告营销案例分析
  • 企业网站建设要求标准说明免费推广途径
  • 国外做水广告网站大全湖北网络推广公司
  • 哪里可以做产品购物网站搜索引擎优化包括哪些
  • 做pc网站排慧聪网
  • vR网站建设程序做网站哪个公司最好
  • 基于jsp网站开发参考文献个人友情链接推广
  • 上海市建设工程信息报送网站适合30岁女人的培训班
  • 青岛网站建设加盟公司怎么提高关键词搜索权重
  • 关于网站开发的技术博客阳城seo排名
  • 推销网站建设站长工具查询网站
  • 在网上做兼职美工有哪些网站西安seo排名外包
  • 峰峰企业做网站推广磁力猫