diff --git a/examples/cpp-simple/server.cc b/examples/cpp-simple/server.cc index 7baa98c819..0963f6358f 100644 --- a/examples/cpp-simple/server.cc +++ b/examples/cpp-simple/server.cc @@ -50,7 +50,7 @@ int main() { std::cout << "Attempting to connect...\n" << std::flush; if (!sdk->Connect()) { - std::cerr << "Could not connect to the sidecar. Exiting!\n"; + std::cerr << "Exiting!\n"; return -1; } std::cout << "...handshake complete.\n" << std::flush; diff --git a/sdks/cpp/src/agones/sdk.cc b/sdks/cpp/src/agones/sdk.cc index cf1a9fb10d..abf069c4e1 100644 --- a/sdks/cpp/src/agones/sdk.cc +++ b/sdks/cpp/src/agones/sdk.cc @@ -20,6 +20,7 @@ namespace agones { struct SDK::SDKImpl { + std::string host_; std::shared_ptr channel_; std::unique_ptr stub_; std::unique_ptr> health_; @@ -27,8 +28,10 @@ struct SDK::SDKImpl { }; SDK::SDK() : pimpl_{std::make_unique()} { - pimpl_->channel_ = grpc::CreateChannel("localhost:59357", - grpc::InsecureChannelCredentials()); + const char* port = std::getenv("AGONES_SDK_GRPC_PORT"); + pimpl_->host_ = std::string("localhost:") + (port ? port : "59357"); + pimpl_->channel_ = + grpc::CreateChannel(pimpl_->host_, grpc::InsecureChannelCredentials()); } SDK::~SDK() {} @@ -37,6 +40,8 @@ bool SDK::Connect() { if (!pimpl_->channel_->WaitForConnected( gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(30, GPR_TIMESPAN)))) { + std::cerr << "Could not connect to the sidecar at " << pimpl_->host_ + << ".\n"; return false; }