当前位置: 首页>>代码示例>>C#>>正文


C# Server.AddListeningPort方法代码示例

本文整理汇总了C#中Grpc.Core.Server.AddListeningPort方法的典型用法代码示例。如果您正苦于以下问题:C# Server.AddListeningPort方法的具体用法?C# Server.AddListeningPort怎么用?C# Server.AddListeningPort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Grpc.Core.Server的用法示例。


在下文中一共展示了Server.AddListeningPort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Init

 public void Init()
 {
     server = new Server();
     server.AddServiceDefinition(ServiceDefinition);
     int port = server.AddListeningPort(Host, Server.PickUnusedPort);
     server.Start();
     channel = new Channel(Host, port);
 }
开发者ID:meisterpeeps,项目名称:grpc,代码行数:8,代码来源:ClientServerTest.cs

示例2: StartAndShutdownServer

 public void StartAndShutdownServer()
 {
     Server server = new Server();
     server.AddListeningPort("localhost", Server.PickUnusedPort);
     server.Start();
     server.ShutdownAsync().Wait();
     GrpcEnvironment.Shutdown();
 }
开发者ID:hmings888,项目名称:grpc,代码行数:8,代码来源:ServerTest.cs

示例3: StartAndShutdownServer

        public void StartAndShutdownServer()
        {
            GrpcEnvironment.Initialize();

            Server server = new Server();
            server.AddListeningPort("localhost:0");
            server.Start();
            server.ShutdownAsync().Wait();

            GrpcEnvironment.Shutdown();
        }
开发者ID:jwatt,项目名称:kythe,代码行数:11,代码来源:ServerTest.cs

示例4: Init

        public void Init()
        {
            serviceImpl = new HealthServiceImpl();

            server = new Server();
            server.AddServiceDefinition(Grpc.Health.V1Alpha.Health.BindService(serviceImpl));
            int port = server.AddListeningPort(Host, Server.PickUnusedPort);
            server.Start();
            channel = new Channel(Host, port);

            client = Grpc.Health.V1Alpha.Health.NewClient(channel);
        }
开发者ID:hmings888,项目名称:grpc,代码行数:12,代码来源:HealthClientServerTest.cs

示例5: Main

        public static void Main(string[] args)
        {
            GrpcEnvironment.Initialize();

            Server server = new Server();
            server.AddServiceDefinition(Greeter.BindService(new GreeterImpl()));
            int port = server.AddListeningPort("localhost", 50051);
            server.Start();

            Console.WriteLine("Greeter server listening on port " + port);
            Console.WriteLine("Press any key to stop the server...");
            Console.ReadKey();

            server.ShutdownAsync().Wait();
            GrpcEnvironment.Shutdown();
        }
开发者ID:hongweiwang,项目名称:grpc-common,代码行数:16,代码来源:Program.cs

示例6: Main

        public static void Main(string[] args)
        {
            string host = "0.0.0.0";

            Server server = new Server();
            server.AddServiceDefinition(Math.BindService(new MathServiceImpl()));
            int port = server.AddListeningPort(host, 23456);
            server.Start();

            Console.WriteLine("MathServer listening on port " + port);

            Console.WriteLine("Press any key to stop the server...");
            Console.ReadKey();

            server.ShutdownAsync().Wait();
            GrpcEnvironment.Shutdown();
        }
开发者ID:hmings888,项目名称:grpc,代码行数:17,代码来源:MathServer.cs

示例7: Main

        static void Main(string[] args)
        {
            var features = RouteGuideUtil.ParseFeatures(RouteGuideUtil.DefaultFeaturesFile);
            GrpcEnvironment.Initialize();

            Server server = new Server();
            server.AddServiceDefinition(RouteGuide.BindService(new RouteGuideImpl(features)));
            int port = server.AddListeningPort("localhost", 50052);
            server.Start();

            Console.WriteLine("RouteGuide server listening on port " + port);
            Console.WriteLine("Press any key to stop the server...");
            Console.ReadKey();

            server.ShutdownAsync().Wait();
            GrpcEnvironment.Shutdown();
        }
开发者ID:hongweiwang,项目名称:grpc-common,代码行数:17,代码来源:Program.cs

示例8: UnaryCall

        public void UnaryCall()
        {
            Server server = new Server();
            server.AddServiceDefinition(
                ServerServiceDefinition.CreateBuilder(serviceName)
                    .AddMethod(unaryEchoStringMethod, HandleUnaryEchoString).Build());

            int port = server.AddListeningPort(host + ":0");
            server.Start();

            using (Channel channel = new Channel(host + ":" + port))
            {
                var call = new Call<string, string>(serviceName, unaryEchoStringMethod, channel, Metadata.Empty);

                Assert.AreEqual("ABC", Calls.BlockingUnaryCall(call, "ABC", default(CancellationToken)));

                Assert.AreEqual("abcdef", Calls.BlockingUnaryCall(call, "abcdef", default(CancellationToken)));
            }

            server.ShutdownAsync().Wait();
        }
开发者ID:jwatt,项目名称:kythe,代码行数:21,代码来源:ClientServerTest.cs

示例9: Init

        public void Init()
        {
            GrpcEnvironment.Initialize();

            server = new Server();
            server.AddServiceDefinition(TestService.BindService(new TestServiceImpl()));
            int port = server.AddListeningPort(host, Server.PickUnusedPort, TestCredentials.CreateTestServerCredentials());
            server.Start();

            var options = new List<ChannelOption>
            {
                new ChannelOption(ChannelOptions.SslTargetNameOverride, TestCredentials.DefaultHostOverride)
            };
            channel = new Channel(host, port, TestCredentials.CreateTestClientCredentials(true), options);
            client = TestService.NewStub(channel);
        }
开发者ID:kdavison,项目名称:grpc,代码行数:16,代码来源:InteropClientServerTest.cs

示例10: Init

        public void Init()
        {
            GrpcEnvironment.Initialize();

            server = new Server();
            server.AddServiceDefinition(TestService.BindService(new TestServiceImpl()));
            int port = server.AddListeningPort(host, Server.PickUnusedPort, TestCredentials.CreateTestServerCredentials());
            server.Start();

            var channelArgs = ChannelArgs.CreateBuilder()
                .AddString(ChannelArgs.SslTargetNameOverrideKey, TestCredentials.DefaultHostOverride).Build();

            channel = new Channel(host + ":" + port, TestCredentials.CreateTestClientCredentials(true), channelArgs);
            client = TestService.NewStub(channel);
        }
开发者ID:mway08,项目名称:grpc,代码行数:15,代码来源:InteropClientServerTest.cs

示例11: Init

        public void Init()
        {
            GrpcEnvironment.Initialize();

            server = new Server();
            server.AddServiceDefinition(Math.BindService(new MathServiceImpl()));
            int port = server.AddListeningPort(host, Server.PickUnusedPort);
            server.Start();
            channel = new Channel(host + ":" + port);

            // TODO(jtattermusch): get rid of the custom header here once we have dedicated tests
            // for header support.
            var stubConfig = new StubConfiguration((headerBuilder) =>
            {
                headerBuilder.Add(new Metadata.MetadataEntry("customHeader", "abcdef"));
            });
            client = Math.NewStub(channel, stubConfig);
        }
开发者ID:mway08,项目名称:grpc,代码行数:18,代码来源:MathClientServerTests.cs

示例12: Run

        private void Run()
        {
            var server = new Server();
            server.AddServiceDefinition(TestService.BindService(new TestServiceImpl()));

            string host = "0.0.0.0";
            int port = options.port.Value;
            if (options.useTls)
            {
                server.AddListeningPort(host, port, TestCredentials.CreateTestServerCredentials());
            }
            else
            {
                server.AddListeningPort(host, options.port.Value);
            }
            Console.WriteLine("Running server on " + string.Format("{0}:{1}", host, port));
            server.Start();

            server.ShutdownTask.Wait();

            GrpcEnvironment.Shutdown();
        }
开发者ID:hmings888,项目名称:grpc,代码行数:22,代码来源:InteropServer.cs

示例13: Init

        public void Init()
        {
            server = new Server();
            server.AddServiceDefinition(Math.BindService(new MathServiceImpl()));
            int port = server.AddListeningPort(host, Server.PickUnusedPort);
            server.Start();
            channel = new Channel(host, port);
            client = Math.NewClient(channel);

            // TODO(jtattermusch): get rid of the custom header here once we have dedicated tests
            // for header support.
            client.HeaderInterceptor = (metadata) =>
            {
                metadata.Add(new Metadata.Entry("customHeader", "abcdef"));
            };
        }
开发者ID:hmings888,项目名称:grpc,代码行数:16,代码来源:MathClientServerTests.cs

示例14: Run

        private void Run()
        {
            GrpcEnvironment.Initialize();

            var server = new Server();
            server.AddServiceDefinition(TestServiceGrpc.BindService(new TestServiceImpl()));

            string addr = "0.0.0.0:" + options.port;
            if (options.useTls)
            {
                server.AddListeningPort(addr, TestCredentials.CreateTestServerCredentials());
            }
            else
            {
                server.AddListeningPort(addr);
            }
            Console.WriteLine("Running server on " + addr);
            server.Start();

            server.ShutdownTask.Wait();

            GrpcEnvironment.Shutdown();
        }
开发者ID:jwatt,项目名称:kythe,代码行数:23,代码来源:InteropServer.cs

示例15: UnaryCallPerformance

        public void UnaryCallPerformance()
        {
            Server server = new Server();
            server.AddServiceDefinition(
                ServerServiceDefinition.CreateBuilder(serviceName)
                .AddMethod(unaryEchoStringMethod, HandleUnaryEchoString).Build());

            int port = server.AddListeningPort(host + ":0");
            server.Start();

            using (Channel channel = new Channel(host + ":" + port))
            {
                var call = new Call<string, string>(serviceName, unaryEchoStringMethod, channel, Metadata.Empty);
                BenchmarkUtil.RunBenchmark(100, 1000,
                                           () => { Calls.BlockingUnaryCall(call, "ABC", default(CancellationToken)); });
            }

            server.ShutdownAsync().Wait();
        }
开发者ID:jwatt,项目名称:kythe,代码行数:19,代码来源:ClientServerTest.cs


注:本文中的Grpc.Core.Server.AddListeningPort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。