public static void Main(string[] args) { //var x = new SurvCenterServiceImpl(); //Task<GeneralReply> r = x.ReEvent(); //r.Wait(); //return; //建立服务器,并绑定服务 Server server = new Server { Services = { SurvCenterService.BindService(new SurvCenterServiceImpl()) }, Ports = { new ServerPort("localhost", Port, ServerCredentials.Insecure) } }; //启动服务器 server.Start(); Console.WriteLine("Greeter server listening on port " + Port); Console.WriteLine("Press any key to stop the server..."); Console.ReadKey(); //结束服务器 server.ShutdownAsync().Wait(); }
/// <summary> /// 启动设备服务 /// </summary> /// <returns></returns> public bool Start(int listenPort = 8000) { try { if (server == null) { ImplSurvCenterService alarmEvtImpl = new ImplSurvCenterService(); alarmEvtImpl.OnNewEvent += AlarmEvtImpl_OnNewEvent; alarmEvtImpl.OnHeartBeat += AlarmEvtImpl_OnHeartBeat; server = new Server { Services = { SurvCenterService.BindService(alarmEvtImpl) }, Ports = { new ServerPort("0.0.0.0", listenPort, ServerCredentials.Insecure) } }; } server.Start(); return(true); } catch (Exception exp) { return(false); } }