Pardon the newbie question. I am getting started with gRPC, and hitting a 
basic issue where the client gets an error code for the RPC call:
Error code: 14 Err msg: Endpoint read failed

TL;DR Server starts fine. Netstat shows it is listening on the port. Client 
fails to connect to netcat on same address as well. 

The service is very simple:
<snip>
syntax = "proto3";

service MySvc { // name edited
   rpc GetVersion(Version) returns (Version) {}
}

message Version {
   int32 version = 1;
}
</snip>

The compilation succeeds with g++ 4.8.5 and  "-Wall". The server starts up 
fine and prints:
<snip>
I0606 16:17:24.415181976    4792 server_builder.cc:247]      Synchronous 
server. Num CQs: 1, Min pollers: 1, Max Pollers: 2147483647, CQ timeout 
(msec): 1000
Server listening on 127.0.0.1:50051
</snip>

The command 'netstat -tulpn | grep ...' shows that the server is listening:
tcp6       0      0 127.0.0.1:50051         :::*                    
LISTEN      4792/./<service-name>

I also ran 'nc -l 127.0.0.1 50051' and executed the client binary. The 
netcat got nothing. So, the issue seems be on the client side.

Here is my client code:
<snip>
class MySvcClient {
public:
   MySvcClient(std::shared_ptr<Channel> channel)
        : stub_(MySvc::NewStub(channel)) {}

   int GetServerVersion(int version) {
      Version client_version, server_version;
      ClientContext ctx;

      client_version.set_version(version);
      Status status = stub_->GetVersion(&ctx, client_version, 
&server_version);

      cout << "Error code: " << status.error_code();
      cout << " Err msg: " << status.error_message() << endl;

      if (status.ok()) {
         cout << "Server version: " << server_version.version() << endl;
         return server_version.version();
      } else {
         cout << "Failed to get Server version: " << endl;
         return -1;
      }
   }

private:
   unique_ptr<MySvc::Stub> stub_;
};

int main(int argc, char** argv) {
   MySvcClient client(grpc::CreateChannel(
      "127.0.0.1:50051", grpc::InsecureChannelCredentials()));
   int myversion = 2;
   int server_version = client.GetServerVersion(myversion);
   cout << "Server version: " << server_version << endl;

   return 0;
}
</snip>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/c9a2c89e-ff6a-4f78-9949-2e626bfa36bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to