/// <summary> /// 启动服务 /// </summary> /// <returns>是否成功</returns> public override bool Start() { if (isListen != 0) { return(true); } if (IsDisposed == 0 && Interlocked.CompareExchange(ref isStart, 1, 0) == 0) { if (!GetRegisterClient(Attribute, Attribute.TcpRegisterName, ref tcpRegisterClient)) { return(false); } if (listen()) { startGetSocket(); if (Attribute.TcpRegisterName != null) { if (tcpRegisterClient.Register(this)) { Log.Info(ServerAttribute.ServerName + " 注册 " + Attribute.Host + ":" + Port.toString() + " => " + Attribute.ClientRegisterHost + ":" + Attribute.ClientRegisterPort.toString(), LogLevel.Info | LogLevel.AutoCSer); } else { Log.Error("TCP 内部服务注册 " + ServerAttribute.ServerName + " 失败 ", LogLevel.Error | LogLevel.AutoCSer); } } return(true); } } return(false); }
/// <summary> /// TCP 内部服务客户端 /// </summary> /// <param name="attribute">TCP服务调用配置</param> /// <param name="log">日志接口</param> public Client(ServerAttribute attribute, ILog log) : base(attribute, log, int.MaxValue) { if (attribute.TcpRegisterName != null) { tcpRegisterClient = AutoCSer.Net.TcpRegister.Client.Get(attribute.TcpRegisterName, Log); tcpRegisterClient.Register(this); } }
/// <summary> /// TCP 内部服务客户端 /// </summary> /// <param name="attribute">TCP服务调用配置</param> /// <param name="onCustomData">自定义数据包处理</param> /// <param name="log">日志接口</param> /// <param name="clientRoute">TCP 客户端路由</param> internal Client(ServerAttribute attribute, Action <SubArray <byte> > onCustomData, ILog log, AutoCSer.Net.TcpServer.ClientLoadRoute <ClientSocketSender> clientRoute) : base(attribute, onCustomData, log) { this.clientRoute = clientRoute; if (attribute.TcpRegisterName != null) { tcpRegisterClient = AutoCSer.Net.TcpRegister.Client.Get(attribute.TcpRegisterName, Log); tcpRegisterClient.Register(this); } }
/// <summary> /// TCP 内部服务客户端 /// </summary> /// <param name="attribute">TCP服务调用配置</param> /// <param name="log">日志接口</param> /// <param name="clientRoute">TCP 客户端路由</param> internal Client(ServerAttribute attribute, ILog log, AutoCSer.Net.TcpServer.ClientLoadRoute <ClientSocketSender> clientRoute) : base(attribute, log) { this.clientRoute = clientRoute; if (attribute.TcpRegisterName != null) { tcpRegisterClient = AutoCSer.Net.TcpRegister.Client.Get(attribute.TcpRegisterName, Log); tcpRegisterClient.Register(this); } }