diff --git a/examples/csharp/Xds/Greeter/Greeter.csproj b/examples/csharp/Xds/Greeter/Greeter.csproj
index 232cf560edf..9351cbcb53a 100644
--- a/examples/csharp/Xds/Greeter/Greeter.csproj
+++ b/examples/csharp/Xds/Greeter/Greeter.csproj
@@ -9,6 +9,7 @@
+
diff --git a/examples/csharp/Xds/GreeterClient/Program.cs b/examples/csharp/Xds/GreeterClient/Program.cs
index 0b2b002b1fd..c6820a8f8d7 100644
--- a/examples/csharp/Xds/GreeterClient/Program.cs
+++ b/examples/csharp/Xds/GreeterClient/Program.cs
@@ -15,16 +15,27 @@
using System;
using Grpc.Core;
using Helloworld;
+using CommandLine;
namespace GreeterClient
{
class Program
{
+ private class Options
+ {
+ [Option("server", Default = "localhost:50051", HelpText = "The address of the server")]
+ public string Server { get; set; }
+ }
+
public static void Main(string[] args)
{
- // TODO: specify server address..
+ Parser.Default.ParseArguments(args)
+ .WithParsed(options => RunClient(options));
+ }
- Channel channel = new Channel("127.0.0.1:50051", ChannelCredentials.Insecure);
+ private static void RunClient(Options options)
+ {
+ Channel channel = new Channel(options.Server, ChannelCredentials.Insecure);
var client = new Greeter.GreeterClient(channel);
String user = "you";
diff --git a/examples/csharp/Xds/GreeterServer/Program.cs b/examples/csharp/Xds/GreeterServer/Program.cs
index e7a2965739f..4c3e46158b3 100644
--- a/examples/csharp/Xds/GreeterServer/Program.cs
+++ b/examples/csharp/Xds/GreeterServer/Program.cs
@@ -22,6 +22,7 @@ using Grpc.Health;
using Grpc.Health.V1;
using Grpc.Reflection;
using Grpc.Reflection.V1Alpha;
+using CommandLine;
namespace GreeterServer
{
@@ -30,16 +31,28 @@ namespace GreeterServer
// Server side handler of the SayHello RPC
public override Task SayHello(HelloRequest request, ServerCallContext context)
{
- String hostName = Dns.GetHostName(); // TODO: make hostname configurable
+ String hostName = Dns.GetHostName();
return Task.FromResult(new HelloReply { Message = $"Hello {request.Name} from {hostName}!"});
}
}
class Program
{
- const int Port = 50051; // TODO: make port configurable
+ class Options
+ {
+ [Option("port", Default = 50051, HelpText = "The port to listen on.")]
+ public int Port { get; set; }
+
+ // TODO: make hostname configurable
+ }
public static void Main(string[] args)
+ {
+ Parser.Default.ParseArguments(args)
+ .WithParsed(options => RunServer(options));
+ }
+
+ private static void RunServer(Options options)
{
var serviceDescriptors = new [] {Greeter.Descriptor, Health.Descriptor, ServerReflection.Descriptor};
var greeterImpl = new GreeterImpl();
@@ -49,7 +62,7 @@ namespace GreeterServer
Server server = new Server
{
Services = { Greeter.BindService(greeterImpl), Health.BindService(healthServiceImpl), ServerReflection.BindService(reflectionImpl) },
- Ports = { new ServerPort("localhost", Port, ServerCredentials.Insecure) } // TODO: don't listen on just localhost
+ Ports = { new ServerPort("[::]", options.Port, ServerCredentials.Insecure) }
};
server.Start();
@@ -61,7 +74,7 @@ namespace GreeterServer
// Mark overall server status as healthy.
healthServiceImpl.SetStatus("", HealthCheckResponse.Types.ServingStatus.Serving);
- Console.WriteLine("Greeter server listening on port " + Port);
+ Console.WriteLine("Greeter server listening on port " + options.Port);
Console.WriteLine("Press any key to stop the server...");
Console.ReadKey();
diff --git a/examples/csharp/Xds/README.md b/examples/csharp/Xds/README.md
index 9b3f939dcf0..ce0aa9f7443 100644
--- a/examples/csharp/Xds/README.md
+++ b/examples/csharp/Xds/README.md
@@ -54,7 +54,7 @@ Finally, run your client:
```
cd GreeterClient
-dotnet run -- xds-experimental:///my-backend
+dotnet run --server xds-experimental:///my-backend
```
VERIFYING THE SERVER