public static void Main(string[] args) { // Connecting to MySQL DB MySqlConnectionStringBuilder connBuilder = new MySqlConnectionStringBuilder(); connBuilder.Add("Database", "shop"); connBuilder.Add("Data Source", "localhost"); connBuilder.Add("User Id", "root"); connBuilder.Add("Password", "admin#123"); connBuilder.Add("SslMode", "none"); MySqlConnection connection = new MySqlConnection(connBuilder.ConnectionString); cmd = connection.CreateCommand(); connection.Open(); // Build a server var server = new Server { Services = { GreetingService.BindService(new GreeterServiceImpl()) }, Ports = { new ServerPort(Host, Port, ServerCredentials.Insecure) } }; // Start server server.Start(); Console.WriteLine("GreeterServer listening on port " + Port); Console.WriteLine("Press any key to stop the server..."); Console.ReadKey(); // Stopping MySql and Server Connection connection.Close(); server.ShutdownAsync().Wait(); }
static void Main(string[] args) { Grpc.Core.Server server = null; try { server = new Grpc.Core.Server() { //Services = {SqrtService.BindService(new SqrtServiceImpl())}, Services = { GreetingService.BindService(new GreetingServiceImpl()) }, //Services = {CalcService.BindService(new CalculatorServiceImpl())}, Ports = { new ServerPort("localhost", port, ServerCredentials.Insecure) } }; server.Start(); Console.WriteLine("Server is listening on port: " + port); Console.ReadKey(); } catch (IOException ex) { Console.WriteLine("server did not start on port: " + port); throw; } finally { if (server != null) { server.ShutdownAsync().Wait(); } } }
static void Main(string[] args) { const int _port = 50056; Grpc.Core.Server server = null; try { server = new Grpc.Core.Server() { Services = { GreetingService.BindService(new GreetingServiceImpl()) }, Ports = { new ServerPort("localhost", _port, ServerCredentials.Insecure) } }; server.Start(); Console.WriteLine(($"The Server is listening on port : {_port}")); Console.ReadKey(); } catch (IOException e) { Console.WriteLine($"Server Connection Error: {e.Message}"); } finally { server?.ShutdownAsync().Wait(); } }
static async Task Main(string[] args) { Server server = null; try { server = new Server() { Services = { GreetingService.BindService(new GreetingServiceImpl()), CalculatorService.BindService(new CalculatorServiceImpl()), CounterService.BindService(new CounterServiceImpl()), UploadService.BindService(new UploadServiceImpl()), ConversationService.BindService(new ConversationServiceImpl()) }, Ports = { new ServerPort("localhost", Port, ServerCredentials.Insecure) } }; server.Start(); Console.WriteLine($"The server is listening on the port : {Port}"); Console.ReadKey(); } catch (IOException ex) { Console.WriteLine($"The server failed to start : {ex.Message}"); throw; } finally { if (server != null) { await server.ShutdownAsync(); } } }
static void Main(string[] args) { Server server = null; try { server = new Server() { Services = { GreetingService.BindService(new GreetingServiceImpl()) }, Ports = { new ServerPort("localhost", Port, ServerCredentials.Insecure) } }; server.Start(); Console.WriteLine("The server is listening on the port: " + Port); Console.ReadKey(); } catch (IOException e) { Console.WriteLine("The server failed to start: " + e.Message); throw; } finally { if (server != null) { server.ShutdownAsync().Wait(); } } }
static async Task Main(string[] args) { Server server = null; try { // reflection-1 var reflectionServiceImpl = new ReflectionServiceImpl( GreetingService.Descriptor , CalculatorService.Descriptor , PrimeNumberDecompositionService.Descriptor , SqrtService.Descriptor , DeadlineService.Descriptor , ServerReflection.Descriptor ); server = new Server { Services = { GreetingService.BindService(new GreetingServiceImplementation()), CalculatorService.BindService(new CalculatorServiceImplementation()), PrimeNumberDecompositionService.BindService(new PrimeNumberDecompositionServiceImplementation()), // errors SqrtService.BindService(new SqrtServiceImplementation()), // deadlines DeadlineService.BindService(new DeadlineServiceImplementation()), // reflection-2 ServerReflection.BindService(reflectionServiceImpl) }, Ports = { await CreateUnsecureServerPort(Host, Port) } }; server.Start(); Console.WriteLine($"Server is listening on {Port}"); Console.ReadLine(); } catch (IOException ex) { Console.WriteLine($"Server failed to start: {ex.Message}"); throw; } catch (Exception ex) { Console.WriteLine($"Server failed: {ex.Message}"); throw; } finally { if (server != null) { await server.ShutdownAsync(); } } }
static void Main(string[] args) { Server server = null; try { var serverCertificate = File.ReadAllText("ssl/server.crt"); var serverKey = File.ReadAllText("ssl/server.key"); var keyCertificatePair = new KeyCertificatePair(serverCertificate, serverKey); var caCertificate = File.ReadAllText("ssl/ca.crt"); var credentials = new SslServerCredentials(new List <KeyCertificatePair>() { keyCertificatePair }, caCertificate, true); // ./evans.exe -r -p 50051 var greetingServiceReflectionServiceImpl = new ReflectionServiceImpl(GreetingService.Descriptor, ServerReflection.Descriptor); var calculatorServiceReflectionServiceImpl = new ReflectionServiceImpl(CalculatorService.Descriptor, ServerReflection.Descriptor); var blogServiceReflectionServiceImpl = new ReflectionServiceImpl(BlogService.Descriptor, ServerReflection.Descriptor); server = new Server() { Services = { BlogService.BindService(new BlogServiceImpl()), ServerReflection.BindService(blogServiceReflectionServiceImpl), GreetingService.BindService(new GreetingServiceImpl()), //ServerReflection.BindService(greetingServiceReflectionServiceImpl), CalculatorService.BindService(new CalculatorServiceImpl()), //ServerReflection.BindService(calculatorServiceReflectionServiceImpl) }, Ports = { new ServerPort("localhost", port, ServerCredentials.Insecure) } }; server.Start(); Console.WriteLine("The server is listening on the port :" + port); Console.ReadKey(); } catch (IOException e) { Console.WriteLine("The server failed to start:" + e.Message); throw; } finally { if (server != null) { server.ShutdownAsync().Wait(); } } }
static void Main(string[] args) { Server server = null; try { var reflectionServiceImpl = new ReflectionServiceImpl(GreetingService.Descriptor, ServerReflection.Descriptor); var serverCert = File.ReadAllText("ssl/server.crt"); var serverKey = File.ReadAllText("ssl/server.key"); var keypair = new KeyCertificatePair(serverCert, serverKey); var cacert = File.ReadAllText("ssl/ca.crt"); var credentials = new SslServerCredentials( new List <KeyCertificatePair>() { keypair }, cacert, true); server = new Server() { Services = { GreetingService.BindService(new GreetingServiceImp()), CalculatorService.BindService(new CalculatorServiceImp()), SqrtService.BindService(new SqrtServiceImpl()), GreetDeadlinesService.BindService(new GreetingDeadlinesImpl()), ServerReflection.BindService(reflectionServiceImpl) }, Ports = { new ServerPort("localhost", Port, ServerCredentials.Insecure) } }; server.Start(); Console.WriteLine("The server is listening on the port {0}", Port); Console.ReadKey(); } catch (IOException e) { Console.WriteLine("The server failed to start: ", e.Message); } finally { if (server != null) { server.ShutdownAsync().Wait(); } } }
static void Main(string[] args) { Server server = null; try { var serverCert = File.ReadAllText("ssl/server.crt"); var serverKey = File.ReadAllText("ssl/server.key"); var keypair = new KeyCertificatePair(serverCert, serverKey); var caCrt = File.ReadAllText("ssl/ca.crt"); var credentials = new SslServerCredentials(new List <KeyCertificatePair>() { keypair }, caCrt, true); server = new Server() { Services = { GreetingService.BindService(new GreetingServiceImpl()), SumService.BindService(new SumServiceImpl()), PrimeNumbersService.BindService(new PrimeNumbersServiceImpl()), AverageService.BindService(new AverageServiceImpl()), MaxService.BindService(new MaxServiceImpl()), SqrtService.BindService(new SquareRootServiceImpl()), ServerReflection.BindService(new ReflectionServiceImpl(GreetingService.Descriptor, ServerReflection.Descriptor)) }, Ports = { new ServerPort("localhost", port, credentials) } }; server.Start(); Console.WriteLine($"Server is listening on port: {port}"); Console.ReadKey(); } catch (IOException e) { Console.WriteLine($"Server failed to start - {e.Message}"); throw; } finally { if (server != null) { server.ShutdownAsync().Wait(); } } }
public void TestServer() { var rootCert = File.ReadAllText($"{Folder}ca.pem"); var keyCertPair = new KeyCertificatePair( File.ReadAllText($"{Folder}server0.pem"), File.ReadAllText($"{Folder}server0.key")); var serverCredentials = new SslServerCredentials(new[] { keyCertPair }, rootCert, SslClientCertificateRequestType.DontRequest); var server = new Server(new[] { new ChannelOption(ChannelOptions.SoReuseport, 0) }) { Ports = { new ServerPort("localhost", 555, serverCredentials) }, }; server.Services.Add(GreetingService.BindService(new GreeterServerImp())); server.Start(); }
static void Main(string[] args) { //FOR SSL------------------------------------ //var serverCert = File.ReadAllText("ssl/server.crt"); //var serverKey = File.ReadAllText("ssl/server.key"); //var keypair = new KeyCertificatePair(serverCert, serverKey); //var caCert = File.ReadAllText("ssl/ca.crt"); //var credentials = new SslServerCredentials(new List<KeyCertificatePair>() { keypair }, caCert, true); //--------------------------------------------------- //FOR REFLECTION var reflectionServiceImpl = new ReflectionServiceImpl(GreetingService.Descriptor, ServerReflection.Descriptor); //------------------------------------------------------- Server server = null; try { server = new Server() { Services = { GreetingService.BindService(new GreetingServiceImpl()), ServerReflection.BindService(reflectionServiceImpl) //FOR REFLECTION }, //it tells server when client calls greet function, it will call the implementaion of it which is GreetingServiceImpl() Ports = { new ServerPort("localhost", Port, ServerCredentials.Insecure) }//WITHOUT SSL //Ports = { new ServerPort("localhost", Port, credentials) }//WITH SSL }; server.Start(); Console.WriteLine("The Server is listening on Port : " + Port); Console.ReadKey(); } catch (IOException ex) { Console.WriteLine("The Server failed to start : " + ex.Message); throw; } finally { if (server != null) { server.ShutdownAsync().Wait();//running synchronously here.can be asyncronous if server and client is in different system } } }
public static void Main(string[] args) { // Build a server var server = new Server { Services = { GreetingService.BindService(new GreeterServiceImpl()) }, Ports = { new ServerPort(Host, Port, ServerCredentials.Insecure) } }; // Start server server.Start(); Console.WriteLine("GreeterServer listening on port " + Port); Console.WriteLine("Press any key to stop the server..."); Console.ReadKey(); server.ShutdownAsync().Wait(); }
static void Main(string[] args) { var serverCert = File.ReadAllText("ssl/server.crt"); var serverKey = File.ReadAllText("ssl/server.key"); var caCert = File.ReadAllText("ssl/ca.crt"); var keyPair = new KeyCertificatePair(serverCert, serverKey); var credentials = new SslServerCredentials(new List <KeyCertificatePair>() { keyPair }, caCert, true); Server server = null; try { server = new Server() { Services = { GreetingService.BindService(new GreetingServiceImpl()), SqrtService.BindService(new SqrtServiceImpl()) }, Ports = { new ServerPort("localhost", port, credentials) } }; server.Start(); Console.WriteLine($"Server listening on port : {port}"); Console.WriteLine("Press any key ..."); Console.ReadKey(); } catch (IOException ex) { Console.WriteLine($"The server failed to start: {ex}"); throw; } finally { if (server != null) { server.ShutdownAsync().Wait(); } } }
public static void Main(string[] args) { // Build a server var server = new Server { Services = { GreetingService.BindService(new GreeterServiceImpl()) }, Ports = { new ServerPort(Host, Port, ServerCredentials.Insecure) } }; CancellationTokenSource tokenSource = new CancellationTokenSource(); var serverTask = RunServiceAsync(server, tokenSource.Token); Console.WriteLine("GreeterServer listening on port " + Port); Console.WriteLine("Press any key to stop the server..."); Console.ReadKey(); tokenSource.Cancel(); Console.WriteLine("Shutting down..."); serverTask.Wait(); }
static void Main(string[] args) { var serverCert = File.ReadAllText("../../../ssl/server.crt"); var serverKey = File.ReadAllText("../../../ssl/server.key"); var caCert = File.ReadAllText("../../../ssl/ca.crt"); var channelCredential = new SslServerCredentials(new List <KeyCertificatePair> { new KeyCertificatePair(serverCert, serverKey) }, caCert, true); var serviceDesc = new ReflectionServiceImpl(GreetingService.Descriptor, ServerReflection.Descriptor); Grpc.Core.Server server = new Grpc.Core.Server { Services = { GreetingService.BindService(new GreetingServiceImpl()), PrimeNumberDecomposition.BindService(new PrimeNumberDecompositionServiceImpl()), SquareRootService.BindService(new SquareRootServiceImpl()), ServerReflection.BindService(serviceDesc) }, //Ports = { new ServerPort("localhost", 5000, ServerCredentials.Insecure) } Ports = { new ServerPort("localhost", 5000, channelCredential) } }; server.Start(); Console.WriteLine("server started..."); Console.ReadLine(); }
static void Main(string[] args) { Server server = null; try { server = new Server { Services = { GreetingService.BindService(new GreetingServiceImplementation()) }, Ports = { new ServerPort("localhost", portNumber, ServerCredentials.Insecure) } }; server.Start(); Console.WriteLine("Server started on port number: " + portNumber); Console.ReadKey(); } catch (IOException exception) { Console.WriteLine("The server failed to start." + exception.Message); throw; } finally { if (server != null) { server.ShutdownAsync().Wait(); } } }
static void Main(string[] args) { Server server = null; try { var keypair = new KeyCertificatePair(File.ReadAllText("ssl/server.crt"), File.ReadAllText("ssl/server.key")); var cacert = File.ReadAllText("ssl/ca.crt"); var credentials = new SslServerCredentials(new List <KeyCertificatePair>() { keypair }, cacert, false); server = new Server() { Services = { GreetingService.BindService(new GreetingServiceImpl()) }, Ports = { new ServerPort("localhost", Port, credentials) } }; server.Start(); Console.WriteLine("The server is listening on the port : " + Port); Console.ReadKey(); } catch (IOException e) { Console.WriteLine("The server failed to start : " + e.Message); throw; } finally { if (server != null) { server.ShutdownAsync().Wait(); } } }