Check for successful connection?

28 views
Skip to first unread message

Christopher Pisz

unread,
Oct 22, 2020, 3:27:37 PM10/22/20
to grpc.io

How can I check if the RPC client actually made a successfull connection to the RPC server when I create the channel and stub?

I want to be able to throw an exception or signal if the connection failed. I am not sure what method qualifies as an "operation" to try here. I don't want to make any of the RPC calls that we defined, as they all have effects that will occur....unless the only option is to go implement some "Hi I am here" RPC method, but that seems silly, no?

void ChatSyncClient::connect(QUrl const& endpoint) 
     disconnect(); 
     // TODO - How do we tell if this fails? 
     // The comments say a lame channel will be returned, where all operations fail 
     // How are we suppose to check right here rather than later? 
     auto channel =    ::grpc::CreateChannel(endpoint.toString().toStdString(), ::grpc::InsecureChannelCredentials()); 
     m_stub = std::make_unique<chat_sync::Chat::Stub>(channel); 
     emit signalOnConnected(); 
}

veb...@google.com

unread,
Jan 15, 2021, 1:36:17 PM1/15/21
to grpc.io
Sorry for the late answer.

As you can said, it can be checked by sending a simple test rpc. Or you can do by monitoring the state of channel via WaitForStateChange method after making the channel start to connect by calling channel->GetState(true) .
Reply all
Reply to author
Forward
0 new messages