public static void SetOptions(StartServiceOptions options) => Options = options;
public bool StartService(StartServiceOptions options) { ApplicationConfiguartion.SetOptions(options); var serverConfig = new TcpSocketSaeaServerConfiguration(); serverConfig.ReuseAddress = false; serverConfig.KeepAlive = true; serverConfig.KeepAliveInterval = 5000; serverConfig.KeepAliveSpanTime = 1000; serverConfig.PendingConnectionBacklog = 0; var ipe = new IPEndPoint(IPAddress.Parse(ApplicationConfiguartion.Options.LocalAddress), ApplicationConfiguartion.Options.ServicePort); _tcpSaeaServer = TcpSocketsFactory.CreateServerAgent(TcpSocketSaeaSessionType.Full, serverConfig, (notify, session) => { if (SynchronizationContext.IsNull()) { NotifyProc(null); } else { SynchronizationContext.Send(NotifyProc, null); } void NotifyProc(object @object) { switch (notify) { case TcpSessionNotify.OnConnected: ApportionDispatcher apportionDispatcher = new ApportionDispatcher(); apportionDispatcher.ApportionTypeHandlerEvent += ApportionTypeHandlerEvent; apportionDispatcher.LogOutputEventHandler += ApportionDispatcher_LogOutputEventHandler; apportionDispatcher.SetSession(session); break; case TcpSessionNotify.OnSend: break; case TcpSessionNotify.OnDataReceiveing: this.OnDataReceiveingHandler(session); break; case TcpSessionNotify.OnClosed: this.OnClosedHandler(session); break; default: break; } } }); try { _tcpSaeaServer.Listen(ipe); LogOutputEventHandler?.Invoke(LogOutLevelType.Debug, $"SiMay中间会话服务器监听 {ipe.Port} 端口启动成功!"); return(true); } catch (Exception ex) { LogOutputEventHandler?.Invoke(LogOutLevelType.Error, $"SiMay中间会话服务器启动发生错误,端口:{ipe.Port} 错误信息:{ex.Message}!"); return(false); } }