コード例 #1
0
ファイル: Server.cs プロジェクト: jwatt/kythe
 // only call before Start()
 public int AddListeningPort(string addr, ServerCredentials credentials)
 {
     using (var nativeCredentials = credentials.ToNativeCredentials())
     {
         return handle.AddListeningPort(addr, nativeCredentials);
     }
 }
コード例 #2
0
ファイル: Server.cs プロジェクト: wfarr/grpc
 // only call before Start()
 public int AddListeningPort(string addr, ServerCredentials credentials)
 {
     using (var nativeCredentials = credentials.ToNativeCredentials())
     {
         return(handle.AddListeningPort(addr, nativeCredentials));
     }
 }
コード例 #3
0
 /// <summary>
 /// Creates a port from an existing <c>ServerPort</c> instance and boundPort value.
 /// </summary>
 internal ServerPort(ServerPort serverPort, int boundPort)
 {
     this.host = serverPort.host;
     this.port = serverPort.port;
     this.credentials = serverPort.credentials;
     this.boundPort = boundPort;
 }
コード例 #4
0
 /// <summary>
 /// Creates a port from an existing <c>ServerPort</c> instance and boundPort value.
 /// </summary>
 internal ServerPort(ServerPort serverPort, int boundPort)
 {
     this.host        = serverPort.host;
     this.port        = serverPort.port;
     this.credentials = serverPort.credentials;
     this.boundPort   = boundPort;
 }
コード例 #5
0
 /// <summary>
 /// Add a secure port on which server should listen.
 /// Only call this before Start().
 /// </summary>
 public int AddListeningPort(string addr, ServerCredentials credentials)
 {
     lock (myLock)
     {
         Preconditions.CheckState(!startRequested);
         using (var nativeCredentials = credentials.ToNativeCredentials())
         {
             return(handle.AddListeningPort(addr, nativeCredentials));
         }
     }
 }
コード例 #6
0
 private int AddListeningPortInternal(string host, int port, ServerCredentials credentials)
 {
     lock (myLock)
     {
         Preconditions.CheckState(!startRequested);
         var address = string.Format("{0}:{1}", host, port);
         if (credentials != null)
         {
             using (var nativeCredentials = credentials.ToNativeCredentials())
             {
                 return(handle.AddListeningPort(address, nativeCredentials));
             }
         }
         else
         {
             return(handle.AddListeningPort(address));
         }
     }
 }
コード例 #7
0
ファイル: Server.cs プロジェクト: hmings888/grpc
 private int AddListeningPortInternal(string host, int port, ServerCredentials credentials)
 {
     lock (myLock)
     {
         Preconditions.CheckState(!startRequested);    
         var address = string.Format("{0}:{1}", host, port);
         if (credentials != null)
         {
             using (var nativeCredentials = credentials.ToNativeCredentials())
             {
                 return handle.AddListeningPort(address, nativeCredentials);
             }
         }
         else
         {
             return handle.AddListeningPort(address);    
         }
     }
 }
コード例 #8
0
ファイル: Server.cs プロジェクト: hmings888/grpc
 /// <summary>
 /// Add a non-secure port on which server should listen.
 /// Only call this before Start().
 /// </summary>
 /// <returns>The port on which server will be listening.</returns>
 /// <param name="host">the host</param>
 /// <param name="port">the port. If zero, an unused port is chosen automatically.</param>
 public int AddListeningPort(string host, int port, ServerCredentials credentials)
 {
     Preconditions.CheckNotNull(credentials);
     return AddListeningPortInternal(host, port, credentials);
 }
コード例 #9
0
 /// <summary>
 /// Creates a new port on which server should listen.
 /// </summary>
 /// <returns>The port on which server will be listening.</returns>
 /// <param name="host">the host</param>
 /// <param name="port">the port. If zero, an unused port is chosen automatically.</param>
 /// <param name="credentials">credentials to use to secure this port.</param>
 public ServerPort(string host, int port, ServerCredentials credentials)
 {
     this.host = GrpcPreconditions.CheckNotNull(host, "host");
     this.port = port;
     this.credentials = GrpcPreconditions.CheckNotNull(credentials, "credentials");
 }
コード例 #10
0
 /// <summary>
 /// Creates a new port on which server should listen.
 /// </summary>
 /// <returns>The port on which server will be listening.</returns>
 /// <param name="host">the host</param>
 /// <param name="port">the port. If zero, an unused port is chosen automatically.</param>
 /// <param name="credentials">credentials to use to secure this port.</param>
 public ServerPort(string host, int port, ServerCredentials credentials)
 {
     this.host        = Preconditions.CheckNotNull(host, "host");
     this.port        = port;
     this.credentials = Preconditions.CheckNotNull(credentials, "credentials");
 }
コード例 #11
0
 /// <summary>
 /// Adds a new port on which server should listen.
 /// <returns>The port on which server will be listening.</returns>
 /// </summary>
 /// <param name="host">the host</param>
 /// <param name="port">the port. If zero, an unused port is chosen automatically.</param>
 /// <param name="credentials">credentials to use to secure this port.</param>
 public int Add(string host, int port, ServerCredentials credentials)
 {
     return(Add(new ServerPort(host, port, credentials)));
 }
コード例 #12
0
 /// <summary>
 /// Add a non-secure port on which server should listen.
 /// Only call this before Start().
 /// </summary>
 /// <returns>The port on which server will be listening.</returns>
 /// <param name="host">the host</param>
 /// <param name="port">the port. If zero, , an unused port is chosen automatically.</param>
 public int AddListeningPort(string host, int port, ServerCredentials credentials)
 {
     Preconditions.CheckNotNull(credentials);
     return(AddListeningPortInternal(host, port, credentials));
 }
コード例 #13
0
ファイル: Program.cs プロジェクト: mxProject/gRPCHelper
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            Server server = new Server();

            try
            {
                SampleServerSettings settings = SampleServerSettings.LoadFromFile("SampleServerSettings.config");

                //ServiceTimeFillterAttribute.DefaultOpenTime = null;
                //ServiceTimeFillterAttribute.DefaultCloseTime = null;

                // regist service.

                GrpcServiceBuilder builder = new GrpcServiceBuilder();

                GrpcServiceBuilderSettings builderSettings = new GrpcServiceBuilderSettings();

                builderSettings.MarshallerFactory = GrpcMarshallerFactory.DefaultInstance;

                builderSettings.PerformanceListener = new GrpcServerPerformanceListener();

                RegistPerformanceEventHandlers(builderSettings.PerformanceListener);

                server.Services.Add(builder.BuildService("PlayerSearch", typeof(PlayerSearch), new PlayerSearchServiceImpl(), builderSettings));


                // regist heartbeat.

                server.Services.Add(GrpcHeartbeat.BuildService());


                // start server.

                Grpc.Core.ServerCredentials credential = Grpc.Core.ServerCredentials.Insecure;

                server.Ports.Add(settings.ServerName, settings.ServerPort, credential);

                Console.WriteLine(string.Format("Starting... {0}:{1}", settings.ServerName, settings.ServerPort));
                server.Start();
                Console.WriteLine("Started.");

                Console.WriteLine("If you want to shutdown, please press any key.");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                Console.WriteLine("In shutdown...");
                try
                {
                    if (server != null)
                    {
                        server.ShutdownAsync().Wait();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
                Console.WriteLine("Shutdown completed.");
            }

            Console.WriteLine("If you want to close, please press any key.");
            Console.ReadLine();
        }
コード例 #14
0
ファイル: Server.cs プロジェクト: rootusr/grpc
 /// <summary>
 /// Add a port on which server should listen.
 /// Only call this before Start().
 /// </summary>
 /// <returns>The port on which server will be listening.</returns>
 /// <param name="host">the host</param>
 /// <param name="port">the port. If zero, an unused port is chosen automatically.</param>
 public int AddPort(string host, int port, ServerCredentials credentials)
 {
     lock (myLock)
     {
         Preconditions.CheckNotNull(credentials);
         Preconditions.CheckState(!startRequested);
         var address = string.Format("{0}:{1}", host, port);
         using (var nativeCredentials = credentials.ToNativeCredentials())
         {
             if (nativeCredentials != null)
             {
                 return handle.AddSecurePort(address, nativeCredentials);
             }
             else
             {
                 return handle.AddInsecurePort(address);
             }
         }
     }
 }