You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

50 lines
1.6 KiB

  1. using Grpc.Core;
  2. using Grpc.Core.Interceptors;
  3. using JT808.DotNetty.Dashbord.GrpcServer.GrpcImpls;
  4. using JT808.DotNetty.Dashbord.GrpcServer.Interceptors;
  5. using JT808.GrpcDashbord.AtomicCounterGrpcService;
  6. using System;
  7. using System.Threading;
  8. using static JT808.GrpcDashbord.AtomicCounterGrpcService.AtomicCounterService;
  9. namespace JT808.DotNetty.Dashbord.GrpcServer
  10. {
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. var server = new Server
  16. {
  17. Services = {
  18. BindService(new JT808AtomicCounterServiceGrpcImpl())
  19. .Intercept(new DemoInterceptor()),
  20. },
  21. Ports = {
  22. new ServerPort("0.0.0.0", 14000,ServerCredentials.Insecure)
  23. }
  24. };
  25. Console.WriteLine("Google Grpc Starting");
  26. foreach (var item in server.Ports)
  27. {
  28. Console.WriteLine(string.Format("RPC server {0} listening on port {1}", item.Host, item.Port));
  29. }
  30. server.Start();
  31. AtomicCounterServiceClient client = new AtomicCounterServiceClient(new Channel("127.0.0.1:14000", ChannelCredentials.Insecure));
  32. Metadata metadata = new Metadata();
  33. metadata.Add("token", "test");
  34. metadata.Add("request", "web");
  35. try
  36. {
  37. var result = client.GetTcpAtomicCounter(new GrpcDashbord.ServiceGrpcBase.EmptyRequest(), metadata);
  38. }
  39. catch (RpcException ex)
  40. {
  41. }
  42. Console.ReadKey();
  43. server.ShutdownAsync().Wait();
  44. }
  45. }
  46. }