Beispiel #1
0
 /// <summary>
 /// TCP 服务客户端套接字
 /// </summary>
 /// <param name="clientCreator">TCP 服务客户端创建器</param>
 /// <param name="ipAddress"></param>
 /// <param name="port"></param>
 /// <param name="maxInputSize"></param>
 internal ClientSocketBase(ClientSocketCreator clientCreator, IPAddress ipAddress, int port, int maxInputSize)
 {
     ClientCreator  = clientCreator;
     this.ipAddress = ipAddress;
     this.port      = port;
     Log            = clientCreator.CommandClient.Log;
     MaxInputSize   = maxInputSize > 0 ? maxInputSize : int.MaxValue;
 }
Beispiel #2
0
        /// <summary>
        /// TCP 服务客户端套接字数据发送
        /// </summary>
        /// <param name="socket">TCP 服务客户端套接字</param>
        internal ClientSocketSenderBase(ClientSocketBase socket)
            : base(socket.Socket)
        {
            clientCreator = socket.ClientCreator;

            this.queueCommandSize = Math.Max(socket.ClientCreator.Attribute.GetQueueCommandSize, 1);
            OutputWaitHandle.Set(0);
        }
Beispiel #3
0
 /// <summary>
 /// TCP 服务客户端
 /// </summary>
 /// <param name="attribute">TCP服务调用配置</param>
 /// <param name="log">日志接口</param>
 public ClientBase(attributeType attribute, ILog log)
     : base(attribute, attribute.GetSendBufferSize, attribute.GetReceiveBufferSize, attribute.ClientSendBufferMaxSize, log)
 {
     OutputSleep    = attribute.GetClientOutputSleep;
     TryCreateSleep = Math.Max(attribute.GetClientTryCreateSleep, 10);
     SocketWait.Set(0);
     clientCreator = new ClientSocketCreator <attributeType>(this);
 }
Beispiel #4
0
 /// <summary>
 /// TCP 服务客户端套接字
 /// </summary>
 /// <param name="clientCreator">TCP 服务客户端创建器</param>
 /// <param name="ipAddress"></param>
 /// <param name="port"></param>
 /// <param name="maxInputSize"></param>
 internal ClientSocketBase(ClientSocketCreator clientCreator, IPAddress ipAddress, int port, int maxInputSize)
 {
     ClientCreator  = clientCreator;
     this.IpAddress = ipAddress;
     this.Port      = port;
     Log            = clientCreator.CommandClient.Log;
     MaxInputSize   = maxInputSize > 0 ? maxInputSize : int.MaxValue;
     LazyLog        = clientCreator.Attribute.ClientLazyLogSeconds > 0 ? new ClientLazyLog(Math.Max(clientCreator.Attribute.ClientLazyLogSeconds + 1, int.MaxValue), this) : ClientLazyLog.Null;
 }
Beispiel #5
0
        /// <summary>
        /// TCP 服务客户端
        /// </summary>
        /// <param name="attribute">TCP服务调用配置</param>
        /// <param name="log">日志接口</param>
        /// <param name="onCustomData">自定义数据包处理</param>
        internal ClientBase(ServerBaseAttribute attribute, ILog log, Action <SubArray <byte> > onCustomData)
            : base(attribute, attribute.GetSendBufferSize, attribute.GetReceiveBufferSize, attribute.ClientSendBufferMaxSize, log)
        {
            OutputSleep         = attribute.GetClientOutputSleep;
            FristTryCreateSleep = Math.Max(attribute.GetClientFirstTryCreateSleep, 10);
            TryCreateSleep      = Math.Max(attribute.GetClientTryCreateSleep, 10);
            SocketWait.Set(0);

            this.onCustomData = onCustomData;
            clientCreator     = new ClientSocketCreator(this);
        }
Beispiel #6
0
 /// <summary>
 /// 移除 TCP 服务客户端套接字
 /// </summary>
 /// <param name="clientSocketCreator">TCP 服务客户端创建器</param>
 /// <param name="socket"></param>
 /// <param name="type"></param>
 internal void CallOnSocket(ClientSocketCreator clientSocketCreator, ClientSocketBase socket, ClientSocketEventParameter.EventType type)
 {
     if (onSocket != null)
     {
         Monitor.Enter(OnSocketLock);
         try
         {
             onSocket(new ClientSocketEventParameter(clientSocketCreator, socket, type));
         }
         catch (Exception error)
         {
             Log.Add(AutoCSer.Log.LogType.Error, error);
         }
         finally { Monitor.Exit(OnSocketLock); }
     }
 }
Beispiel #7
0
 internal void CallOnSetSocketOnly(ClientSocketCreator clientSocketCreator, ClientSocketBase socket)
 {
     onSocket(new ClientSocketEventParameter(clientSocketCreator, socket, ClientSocketEventParameter.EventType.SetSocket));
 }
Beispiel #8
0
 /// <summary>
 /// 创建套接字
 /// </summary>
 /// <param name="clientCreator"></param>
 /// <param name="ipAddress"></param>
 /// <param name="port"></param>
 /// <param name="createVersion"></param>
 internal abstract ClientSocketBase CreateSocketByCreator(ClientSocketCreator clientCreator, IPAddress ipAddress, int port, int createVersion);
 /// <summary>
 /// TCP 客户端套接字事件参数
 /// </summary>
 /// <param name="creator">TCP 服务客户端创建器</param>
 /// <param name="socket">TCP 服务客户端套接字</param>
 /// <param name="type">事件类型</param>
 internal ClientSocketEventParameter(ClientSocketCreator creator, ClientSocketBase socket, EventType type)
 {
     Creator = creator;
     Socket  = socket;
     Type    = type;
 }
Beispiel #10
0
 ///// <summary>
 ///// 保持回调命令会话标识
 ///// </summary>
 //private uint keepCallbackCommandIndex = uint.MaxValue;
 /// <summary>
 /// TCP 服务客户端套接字
 /// </summary>
 /// <param name="clientCreator">TCP 服务客户端创建器</param>
 /// <param name="ipAddress"></param>
 /// <param name="port"></param>
 /// <param name="createVersion"></param>
 /// <param name="maxInputSize"></param>
 internal ClientSocket(ClientSocketCreator clientCreator, IPAddress ipAddress, int port, int createVersion, int maxInputSize)
     : base(clientCreator, ipAddress, port, maxInputSize)
 {
     CreateVersion = createVersion;
     AutoCSer.Threading.ThreadPool.TinyBackground.FastStart(this, AutoCSer.Threading.ThreadTaskType.TcpClientSocketBaseCreate);
 }