Reputation: 695
I have a gRPC client calling into a server on the same machine and client code uses the channel created with:
Channel channel = new Channel("localhost", 11112, ChannelCredentials.Insecure);
This works well, and I'm getting the reply as expected.
However, if I replace "localhost" with the actual machine name (FQDN) or IP address, I'm getting an error:
Status(StatusCode="Unavailable", Detail="failed to connect to all addresses", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1616190440.553000000","description":"Failed to pick subchannel","file":"..\..\..\src\core\ext\filters\client_channel\client_channel.cc","file_line":5397,"referenced_errors":[{"created":"@1616190440.553000000","description":"failed to connect to all addresses","file":"..\..\..\src\core\ext\filters\client_channel\lb_policy\pick_first\pick_first.cc","file_line":398,"grpc_status":14}]}")
I also tested starting the server on a remote machine and having the client call into that remote machine (by name or IP) when creating the channel, but got the same failure. The application is written in C# .NET Core 3.2 as a Console application. Nuget packages included are: Google.Protobuf, Grpc.Core, Grpc.Tools.
Not sure what is wrong in my code or whether something is not setup properly on my machine.
Here's the reset of the relevant client code:
MWCS.McpsServer.McpsServerClient client = new MWCS.McpsServer.McpsServerClient(channel);
var data = new ProcessResponseInput() { ClientID = clientID };
var options = new CallOptions();
try {
var res = client.ProcessResponse(data, options);
return res;
} catch (RpcException ex) {
StandardOutput so = new StandardOutput() { ExitCode = 1, Message = ex.Message };
return so;
}
Upvotes: 1
Views: 3419
Reputation: 695
To resolve this, I actually had to fix the server code. I should have used "0.0.0.0"
instead of "localhost"
in the bind address on the server. Looks like when setting the server to localhost it is not visible outside the computer.
Here's how I have the server started now (after the replacement):
_server = new Server() {
Services = { McpsServer.BindService(new McpcServerImplementation()) },
Ports = { new ServerPort("0.0.0.0", 11112, ServerCredentials.Insecure) }
};
Upvotes: 1