我很难与部署在 Herkou 上的 gRPC 服务器通信。
这是我使用 NodeJS 在 gRPC 服务器上监听的方式:
server.js
init() {
let grpcServer = new grpc.Server();
grpcServer.addService(services.LocationManagementService, LocationManager);
grpcServer.bindAsync('0.0.0.0:50051', grpc.ServerCredentials.createInsecure(), () => {
grpcServer.start();
console.log("GRPC Server Started");
});
}
其中 LocationManager.js
如下
const LocationManager = {
updateLocation: (call, callback) => {
console.log("The Location Update Function Has Being called");
let locationUpdateResponse = new messages.LocationDataResponse();
let request = call.request;
let authParams = request.getAuthParams();
let locationUpdateTarget = request.getLocationUpdateTarget();
},
queryLocation: (call, callback) => {
let locationQueryResponse = new messages.LocationDataResponse();
}
}
module.exports = LocationManager;
为 Flutter 生成客户端库并使用如下:
static ClientChannel clientChannel() {
return ClientChannel(
myappname.herokuapp.com,
port:50051,
options: ChannelOptions(
credentials: ChannelCredentials.insecure(),
),
);
}
LocationManagementClient locationManagementClient =
LocationManagementClient(clientChannel());
但我一直得到的是:
gRPC Error (code: 14, codeName: UNAVAILABLE, message: Error connecting: SocketException: OS Error: Connection timed out, errno = 110, address = myappname.herokuapp.com, port = 32788, details: null, rawResponse: null)
任何见解将不胜感激。
谢谢。