我试图测试我的grpc客户端连接使用下面的代码。我有。net核心grpc服务器和使用节点js grpc客户端连接。但得到“未能连接到所有地址”错误。但无法连接。net grpc服务器到。net grpc客户端。任何帮助非常感谢。
不确定IM是否丢失了下面grpc客户端代码中的任何内容。
'use strict';
//Same as the other projects we import fs for reading documents, in this case employees.js json
const fs = require('fs');
//Importing GRPC and the proto loader
const grpc = require('grpc');
const loader = require('@grpc/proto-loader');
//reads the proto
const packageDefinition = loader.loadSync('Repository.proto', {
keepCase: false,
longs: String,
enums: String,
defaults: true,
oneofs: true
});
//Loads the proto file to be used in constant pkg
const pkg = grpc.loadPackageDefinition(packageDefinition);
//Creates server
const PORT = 5001;
//console.log(pkg);
const client = new pkg.repository.Repository('localhost:5001', grpc.credentials.createInsecure());
client.GetUpdates({}, function (err, response) {
console.log("----Response error----");
if (err) {
console.log(err);
} else {
console.log(response);
}
});
我得到下面的错误:
{ Error: 14 UNAVAILABLE: failed to connect to all addresses
at Object.exports.createStatusError (/mnt/c/Users/ht9638/Desktop/workspace/current-workspace/gRPCNodeJS/firstService/node_modules/grpc/src/common.js:91:15)
at Object.onReceiveStatus (/mnt/c/Users/ht9638/Desktop/workspace/current-workspace/gRPCNodeJS/firstService/node_modules/grpc/src/client_interceptors.js:1209:28)
at InterceptingListener._callNext (/mnt/c/Users/ht9638/Desktop/workspace/current-workspace/gRPCNodeJS/firstService/node_modules/grpc/src/client_interceptors.js:568:42)
at InterceptingListener.onReceiveStatus (/mnt/c/Users/ht9638/Desktop/workspace/current-workspace/gRPCNodeJS/firstService/node_modules/grpc/src/client_interceptors.js:618:8)
at callback (/mnt/c/Users/ht9638/Desktop/workspace/current-workspace/gRPCNodeJS/firstService/node_modules/grpc/src/client_interceptors.js:847:24)
code: 14,
metadata: Metadata { _internal_repr: {}, flags: 0 },
details: 'failed to connect to all addresses' }
有人能帮我解决这个问题吗?
1条答案
按热度按时间zbq4xfa01#
当我尝试按照官方文档中的gRPCnodejs教程学习时,遇到了同样的问题
根本原因(对我而言):端口50051是从主文档使用的默认端口,当我检查我的笔记本电脑上正在使用的端口列表时,转出端口50051由“NVIDIA Web helperiderexe”使用。
我是如何发现这一点的:我尝试将端口稍微更改为50052,并将错误记录到console.log中,结果显示为预期的