public void StartServer() { if (_Server != null) { return; } try { _Server = new Server { Services = { HelloService.BindService(new HelloServiceImpl()) }, Ports = { new ServerPort("localhost", 0, ServerCredentials.Insecure) } }; _Server.Start(); DontDestroyOnLoad(gameObject); SceneManager.LoadScene("PlayScene"); Debug.Log($"Server started on port : {_Server.Ports.FirstOrDefault().BoundPort}"); } catch (Exception exception) { Debug.LogError(exception.Message); _Server = null; } }
public HelloServer() { _server = new Server { Services = { HelloService.BindService(new HelloServiceImplementation()) }, Ports = { new ServerPort("localhost", 1234, ServerCredentials.Insecure) } }; }
void OnEnable() { _grpcServer = new Server { Ports = { new ServerPort("0.0.0.0", ServerPort, ServerCredentials.Insecure) } }; _grpcServer.Services.Add(HelloService.BindService(new HelloServiceImpl(this))); _grpcServer.Start(); Debug.Log($"GRPC Server running on port {ServerPort}"); }
static void Main(string[] args) { var server = new Server() { Services = { HelloService.BindService(new HelloServiceImp()) }, Ports = { new ServerPort("localhost", 8888, ServerCredentials.Insecure) } }; server.Start(); Console.WriteLine("Enter any key to stop"); Console.ReadKey(); Console.WriteLine("Hello World!"); }
static void Main(string[] args) { _server = new Server { Services = { HelloService.BindService(new GrpcImpl()) }, Ports = { new ServerPort("localhost", 8088, ServerCredentials.Insecure) } }; _server.Start(); Console.WriteLine("grpc ServerListening On Port 8088"); Console.WriteLine("任意键退出..."); Console.ReadKey(); _server?.ShutdownAsync().Wait(); }
static void Main(string[] args) { if (args.Length != 1) { throw new InvalidOperationException("args.Length must be 2 but is " + args.Length); } var command = args[0]; var port = 8088; if (command.ToLower() == "server") { Server server = new Server { Services = { HelloService.BindService(new HelloServiceImpl()) }, Ports = { new ServerPort("localhost", port, ServerCredentials.Insecure) } }; server.Start(); Console.WriteLine("RouteGuide server listening on port " + port); Console.WriteLine("Press any key to stop the server..."); Console.ReadKey(); server.ShutdownAsync().Wait(); } else if (command.ToLower() == "client") { Channel channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure); var client = new HelloService.HelloServiceClient(channel); // YOUR CODE GOES HERE var reply = client.SayHello(new HelloRequest { Name = "jiannan" }); Console.WriteLine("Reply: " + reply.Message); channel.ShutdownAsync().Wait(); } else { throw new InvalidOperationException("do not support command: " + command); } }