简体   繁体   中英

GRPC client Error: 14 UNAVAILABLE: failed to connect to all addresses

Im trying to test my grpc client connection using below code. I have .net core grpc server and using node js grpc client to connect. But getting "failed to connect to all addresses" error. BUt able to connect .net grpc server to .net grpc client. Any help much appreciated.

Not sure if im missing anything from below grpc client code.

'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);
  }
});

im getting below error:

{ 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' }

Can someone please help me on this issue.

I have the same issue when I tried to follow gRPC nodejs tutorials from the official documentation

Root cause(for me): port 50051 are the default port used from the main documentation, when i check the list of the port being used on my laptop, turn out that port 50051 used by "NVIDIA Web Helper.exe".

How i find this out: I tried to change the port slightly to 50052 and console.log the err and it shows as expected在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM