gRPC fails when using two machines - simple c#.Net server and client

Viewed 309

For years, I've been getting by without making any posts of my own here on Stack. Thanks to the numerous posts I always found a solution sooner or later - thanks for that!!! Until now...

In the course of a project I want to use gRPC for communication between two machines to exchange measurement data. (gRPC 2.35.0)

The structure is based on the grpc.io basic tutorial.

Server

AkZentConnectionPointService gRPCService = new AkZentConnectionPointService();

//var cacert = File.ReadAllText(this.Main.WorkingFolder + "ca.crt");
//var servercert = File.ReadAllText(this.Main.WorkingFolder + "server.crt");
//var serverkey = File.ReadAllText(this.Main.WorkingFolder + "server.key");
//var keypair = new KeyCertificatePair(servercert, serverkey);
//var sslCredentials = new SslServerCredentials(new List<KeyCertificatePair>() { keypair }, cacert, false);

Server server = new Server
{                    
    Services = { AkZentConnectionPoint.BindService(gRPCService) },
    //Ports = { new ServerPort("localhost", this.Main.UserSettings.gRPCPort, sslCredentials) }
    Ports = { new ServerPort("localhost", this.Main.UserSettings.gRPCPort, ServerCredentials.Insecure) }
};
server.Start();   

Client

//var cacert = File.ReadAllText(this.WorkingFolder + "ca.crt");
//var clientcert = File.ReadAllText(this.WorkingFolder + "client.crt");
//var clientkey = File.ReadAllText(this.WorkingFolder + "client.key");                
//var ssl = new SslCredentials(cacert, new KeyCertificatePair(clientcert, clientkey));                

// Start grpc connection to AkZentBridgeService
//grpcChannel = new Channel(this.UserSettings.HostAddress, this.UserSettings.HostPort, ssl);              
grpcChannel = new Channel(this.UserSettings.HostAddress, this.UserSettings.HostPort, ChannelCredentials.Insecure);              
grpcClient = new AkZentConnectionPoint.AkZentConnectionPointClient(grpcChannel);

if (grpcClient.GetState(new Empty()).Value == "Blub")
    Console.WriteLine("Blub");

Run server/client on one machine, everything works fine. On two separate machines it does not work. The machines are connected locally via network - simple setup. Mashine - Switch - Machine.

What I tried

  • Both maschines can ping each other.
  • I also adjusted the firewall on both machines with appropriate rules.
  • In between I thought SSL could be the solution - pure desperation

More or less the only thing I understand from the error log , is "Failed to connect". Am I missing something fundamental? Is gRPC suitable at all, since it uses http2. Unfortunately I am still very inexperienced at this point.

D0307 00:32:44.967118 Grpc.Core.Internal.UnmanagedLibrary Attempting to load native library "C:\visionfab\rpcB\grpc_csharp_ext.x86.dll"
D0307 00:32:45.033122 Grpc.Core.Internal.NativeExtension gRPC native library loaded successfully.
D0307 00:32:45.042123 0..\..\..\src\core\ext\filters\client_channel\lb_policy_registry.cc:42: registering LB policy factory for "grpclb"
D0307 00:32:45.042123 0..\..\..\src\core\ext\filters\client_channel\lb_policy_registry.cc:42: registering LB policy factory for "priority_experimental"
D0307 00:32:45.042123 0..\..\..\src\core\ext\filters\client_channel\lb_policy_registry.cc:42: registering LB policy factory for "weighted_target_experimental"
D0307 00:32:45.042123 0..\..\..\src\core\ext\filters\client_channel\lb_policy_registry.cc:42: registering LB policy factory for "pick_first"
D0307 00:32:45.042123 0..\..\..\src\core\ext\filters\client_channel\lb_policy_registry.cc:42: registering LB policy factory for "round_robin"
D0307 00:32:45.043123 0..\..\..\src\core\ext\filters\client_channel\resolver\dns\c_ares\dns_resolver_ares.cc:507: Using ares dns resolver
D0307 00:32:45.043123 0..\..\..\src\core\ext\filters\client_channel\lb_policy_registry.cc:42: registering LB policy factory for "cds_experimental"
D0307 00:32:45.044123 0..\..\..\src\core\ext\filters\client_channel\lb_policy_registry.cc:42: registering LB policy factory for "eds_experimental"
D0307 00:32:45.044123 0..\..\..\src\core\ext\filters\client_channel\lb_policy_registry.cc:42: registering LB policy factory for "xds_cluster_impl_experimental"
D0307 00:32:45.044123 0..\..\..\src\core\ext\filters\client_channel\lb_policy_registry.cc:42: registering LB policy factory for "xds_cluster_manager_experimental"
D0307 00:32:45.105126 0..\..\..\src\core\ext\filters\client_channel\resolver\dns\c_ares\dns_resolver_ares.cc:185: (c - ares resolver) resolver: 005886B8 AresDnsResolver::StartLocked() is called.
D0307 00:32:45.106126 0..\..\..\src\core\ext\filters\client_channel\resolver\dns\c_ares\grpc_ares_wrapper.cc:648: (c-ares resolver) request:0056BBE8 c-ares grpc_dns_lookup_ares_locked_impl name=172.16.21.1:50052, default_port=https
I0307 00:32:45.108126 0 ..\..\..\src\core\ext\filters\client_channel\resolver\dns\c_ares\grpc_ares_wrapper.cc:130: (c-ares resolver) request:0056BBE8 c-ares address sorting: input[0]=172.16.21.1:50052
I0307 00:32:45.110126 0 ..\..\..\src\core\ext\filters\client_channel\resolver\dns\c_ares\grpc_ares_wrapper.cc:130: (c-ares resolver) request:0056BBE8 c-ares address sorting: output[0]=172.16.21.1:50052
D0307 00:32:45.111127 0 ..\..\..\src\core\ext\filters\client_channel\resolver\dns\c_ares\dns_resolver_ares.cc:449: (c-ares resolver) resolver:005886B8 Started resolving. pending_request_:0056BBE8
I0307 00:33:05.105270 0 ..\..\..\src\core\ext\filters\client_channel\subchannel.cc:1076: Connect failed: {"created":"@1615073585.105000000","description":"socket is null","file":"..\..\..\src\core\lib\iomgr\tcp_client_windows.cc","file_line":113}
D0307 00:33:05.105270 0 ..\..\..\src\core\ext\filters\client_channel\resolver\dns\c_ares\dns_resolver_ares.cc:418: (c-ares resolver) resolver:005886B8 In cooldown from last resolution (from 20000 ms ago). Will resolve again in 10000 ms
I0307 00:33:05.106270 0 ..\..\..\src\core\ext\filters\client_channel\subchannel.cc:1013: Subchannel 005309D8: Retry immediately
I0307 00:33:05.106270 0 ..\..\..\src\core\ext\filters\client_channel\subchannel.cc:1040: Failed to connect to channel, retrying

Thanks in advance!

2 Answers

The world makes sense again.

Server server = new Server
{                    
   Services = { AkZentConnectionPoint.BindService(gRPCService) },
   //Ports = { new ServerPort("localhost", this.Main.UserSettings.gRPCPort, sslCredentials) }
   Ports = { new ServerPort("localhost", this.Main.UserSettings.gRPCPort, ServerCredentials.Insecure) }
};
server.Start();

Stupid error, I failed to change "localhost" to the IP in the server-side code.

Ports = { new ServerPort("172.16.21.1", this.Main.UserSettings.gRPCPort, ServerCredentials.Insecure) }
Related