Exemplo n.º 1
0
 /// <summary>
 /// TCP调用客户端
 /// </summary>
 /// <param name="attribute">TCP调用服务器端配置信息</param>
 /// <param name="clientRoute">TCP 客户端路由</param>
 /// <param name="onCustomData">自定义数据包处理</param>
 /// <param name="log">日志接口</param>
 public TcpOpenClient(AutoCSer.Net.TcpOpenServer.ServerAttribute attribute = null, AutoCSer.Net.TcpServer.ClientLoadRoute <AutoCSer.Net.TcpOpenServer.ClientSocketSender> clientRoute = null, Action <SubArray <byte> > onCustomData = null, AutoCSer.Log.ILog log = null)
 {
     if (attribute == null)
     {
         attribute = AutoCSer.Config.Loader.Get <AutoCSer.Net.TcpOpenServer.ServerAttribute>("AutoCSer.Example.TcpOpenServer.Static") ?? _DefaultServerAttribute_;
         if (attribute.Name == null)
         {
             attribute.Name = "AutoCSer.Example.TcpOpenServer.Static";
         }
     }
     _TcpClient_ = new AutoCSer.Net.TcpOpenServer.Client <TcpOpenClient>(this, attribute, onCustomData, log, clientRoute);
     if (attribute.IsAutoClient)
     {
         _TcpClient_.TryCreateSocket();
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// TCP调用客户端
 /// </summary>
 /// <param name="attribute">TCP调用服务器端配置信息</param>
 /// <param name="log">日志接口</param>
 public TcpOpenSimpleClient(AutoCSer.Net.TcpOpenSimpleServer.ServerAttribute attribute = null, AutoCSer.Log.ILog log = null)
 {
     if (attribute == null)
     {
         attribute = AutoCSer.Config.Loader.Get <AutoCSer.Net.TcpOpenSimpleServer.ServerAttribute>("AutoCSer.Example.TcpOpenSimpleServer.Field") ?? _DefaultServerAttribute_;
         if (attribute.Name == null)
         {
             attribute.Name = "AutoCSer.Example.TcpOpenSimpleServer.Field";
         }
     }
     _TcpClient_ = new AutoCSer.Net.TcpOpenSimpleServer.Client <TcpOpenSimpleClient>(this, attribute, log);
     if (attribute.IsAutoClient)
     {
         _TcpClient_.TryCreateSocket();
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// 队列线程
 /// </summary>
 /// <param name="onPacket">数据包处理委托</param>
 /// <param name="log">日志处理</param>
 internal QueueTask(Action <Buffer> onPacket, AutoCSer.Log.ILog log)
 {
     this.onPacket = onPacket;
     this.log      = log;
 }
 /// <summary>
 /// TCP调用客户端
 /// </summary>
 /// <param name="attribute">TCP调用服务器端配置信息</param>
 /// <param name="clientRoute">TCP 客户端路由</param>
 /// <param name="log">日志接口</param>
 public TcpOpenStreamClient(AutoCSer.Net.TcpOpenStreamServer.ServerAttribute attribute = null, AutoCSer.Net.TcpServer.ClientLoadRoute <AutoCSer.Net.TcpOpenStreamServer.ClientSocketSender> clientRoute = null, AutoCSer.Log.ILog log = null)
 {
     if (attribute == null)
     {
         attribute = AutoCSer.Config.Loader.Get <AutoCSer.Net.TcpOpenStreamServer.ServerAttribute>("AutoCSer.Example.TcpOpenStreamServer.SendOnly") ?? _DefaultServerAttribute_;
         if (attribute.Name == null)
         {
             attribute.Name = "AutoCSer.Example.TcpOpenStreamServer.SendOnly";
         }
     }
     _TcpClient_ = new AutoCSer.Net.TcpOpenStreamServer.Client <TcpOpenStreamClient>(this, attribute, log, clientRoute);
     if (attribute.IsAutoClient)
     {
         _TcpClient_.TryCreateSocket();
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// 获取电子邮件发送器
 /// </summary>
 /// <param name="message">邮件信息</param>
 /// <param name="smtpClient">STMP客户端</param>
 /// <param name="onSend">邮件发送回调</param>
 /// <param name="log">日志处理</param>
 /// <returns>电子邮件发送器</returns>
 internal void Send(MailMessage message, SmtpClient smtpClient, Action <Exception> onSend, AutoCSer.Log.ILog log)
 {
     this.message              = message;
     this.log                  = log;
     callback                  = onSend;
     smtpClient.SendCompleted += this.onSend;
     smtpClient.SendAsync(message, this);
 }
Exemplo n.º 6
0
 /// <summary>
 /// AutoCSer.TestCase.TcpOpenStreamServerPerformance.OpenStreamServer TCP调用服务端
 /// </summary>
 /// <param name="attribute">TCP调用服务器端配置信息</param>
 /// <param name="value">TCP服务目标对象</param>
 /// <param name="log">日志接口</param>
 public TcpOpenStreamServer(AutoCSer.Net.TcpOpenStreamServer.ServerAttribute attribute = null, Func <System.Net.Sockets.Socket, bool> verify = null, AutoCSer.TestCase.TcpOpenStreamServerPerformance.OpenStreamServer value = null, AutoCSer.Log.ILog log = null)
     : base(attribute ?? (attribute = AutoCSer.Net.TcpOpenStreamServer.ServerAttribute.GetConfig("AutoCSer.TestCase.TcpOpenStreamServerPerformance.OpenStreamServer", typeof(AutoCSer.TestCase.TcpOpenStreamServerPerformance.OpenStreamServer))), verify, log)
 {
     Value = value ?? new AutoCSer.TestCase.TcpOpenStreamServerPerformance.OpenStreamServer();
     setCommandData(2);
     setCommand(0);
     setCommand(1);
     if (attribute.IsAutoServer)
     {
         Start();
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// 多消费者消息队列 客户端消费者
 /// </summary>
 /// <param name="messageQueue">队列消费节点</param>
 /// <param name="onMessage">消息处理委托,直接在 Socket 接收数据的 IO 线程中处理以避免线程调度,适应于快速结束的非阻塞函数;需要知道的是这种模式下如果产生阻塞会造成 Socket 停止接收数据甚至死锁</param>
 /// <param name="config">队列数据 读取配置</param>
 /// <param name="readerIndex">读取编号</param>
 /// <param name="log">日志处理</param>
 public ConsumerStream(DataStructure.MessageQueue.QueueConsumers <valueType> messageQueue, Action <valueType> onMessage, ConsumerConfig config, IConvertible readerIndex, AutoCSer.Log.ILog log = null) : this(messageQueue, onMessage, config, readerIndex.ToInt32(null), log)
 {
 }
 /// <summary>
 /// TCP调用客户端
 /// </summary>
 /// <param name="attribute">TCP调用服务器端配置信息</param>
 /// <param name="log">日志接口</param>
 public TcpOpenStreamClient(AutoCSer.Net.TcpOpenStreamServer.ServerAttribute attribute = null, AutoCSer.Log.ILog log = null)
 {
     if (attribute == null)
     {
         attribute = AutoCSer.Config.Loader.Get <AutoCSer.Net.TcpOpenStreamServer.ServerAttribute>("AutoCSer.Example.TcpOpenStreamServer.RefOut") ?? AutoCSer.Json.Parser.Parse <AutoCSer.Net.TcpOpenStreamServer.ServerAttribute>(@"{""CheckSeconds"":59,""ClientOutputSleep"":-1,""ClientSegmentationCopyPath"":null,""ClientSendBufferMaxSize"":0x100000,""ClientTryCreateSleep"":1000,""GenericType"":null,""Host"":""127.0.0.1"",""IsAttribute"":true,""IsAutoClient"":false,""IsAutoServer"":true,""IsBaseTypeAttribute"":false,""IsClientAwaiter"":false,""IsCompileSerialize"":true,""IsJsonSerialize"":true,""IsMarkData"":false,""IsSegmentation"":true,""IsServerBuildOutputThread"":false,""IsSimpleSerialize"":true,""MaxInputSize"":0x3FF4,""MaxVerifyDataSize"":1024,""MemberFilters"":""Instance"",""MinCompressSize"":0,""Name"":null,""Port"":0x3588,""ReceiveBufferSize"":""Kilobyte8"",""ReceiveVerifyCommandSeconds"":9,""SendBufferSize"":""Kilobyte8"",""ServerOutputSleep"":-1,""ServerSendBufferMaxSize"":0,""ServerTaskType"":""Queue"",""VerifyString"":null,""TypeId"":{}}");
         if (attribute.Name == null)
         {
             attribute.Name = "AutoCSer.Example.TcpOpenStreamServer.RefOut";
         }
     }
     _TcpClient_ = new AutoCSer.Net.TcpOpenStreamServer.Client <TcpOpenStreamClient>(this, attribute, log);
     if (attribute.IsAutoClient)
     {
         _TcpClient_.TryCreateSocket();
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// 原始套接字监听
        /// </summary>
        /// <param name="ipAddress">监听地址</param>
        /// <param name="onPacket">数据包处理委托</param>
        /// <param name="packetSize">数据包字节数</param>
        /// <param name="log">日志处理</param>
        public Listener(IPAddress ipAddress, Action <Buffer> onPacket, int packetSize = defaultBufferSize, AutoCSer.Log.ILog log = null)
        {
            if (onPacket == null)
            {
                throw new ArgumentNullException();
            }
            if (packetSize <= 0)
            {
                packetSize = defaultBufferSize;
            }
            else if (packetSize > BufferPool.Size)
            {
                packetSize = BufferPool.Size;
            }
            this.packetSize = packetSize;
            maxBufferIndex  = BufferPool.Size - packetSize;
            this.log        = log ?? AutoCSer.Log.Pub.Log;
            ipEndPoint      = new IPEndPoint(ipAddress, 0);
#if DOTNET2
            onReceiveAsyncCallback = onReceive;
#else
            async            = AutoCSer.Net.SocketAsyncEventArgsPool.Get();
            async.UserToken  = this;
            async.Completed += onReceive;
#endif
            queueTask = new QueueTask(onPacket, this.log);
            AutoCSer.Threading.ThreadPool.TinyBackground.FastStart(start);
        }
Exemplo n.º 10
0
 /// <summary>
 /// 多消费者消息队列 客户端消费者
 /// </summary>
 /// <param name="messageQueue">队列消费节点</param>
 /// <param name="onMessage">消息处理委托,直接在 Socket 接收数据的 IO 线程中处理以避免线程调度,适应于快速结束的非阻塞函数;需要知道的是这种模式下如果产生阻塞会造成 Socket 停止接收数据甚至死锁</param>
 /// <param name="config">队列数据 读取配置</param>
 /// <param name="readerIndex">读取编号</param>
 /// <param name="log">日志处理</param>
 public ConsumerStream(DataStructure.MessageQueue.QueueConsumers <valueType> messageQueue, Action <valueType> onMessage, ConsumerConfig config, int readerIndex, AutoCSer.Log.ILog log = null) : base(messageQueue.ClientDataStructure.Client.MasterClient, config, log, getReaderIndexNode(messageQueue, readerIndex))
 {
     if (onMessage == null)
     {
         throw new ArgumentNullException();
     }
     this.onMessage = onMessage;
     setCheckSocketVersion(onClientSocket);
 }
Exemplo n.º 11
0
 /// <summary>
 /// 消息队列 客户端消费者
 /// </summary>
 /// <param name="messageQueue">队列消费节点</param>
 /// <param name="onMessage">消息处理委托</param>
 /// <param name="config">队列数据 读取配置</param>
 /// <param name="log">日志处理</param>
 public Consumer(DataStructure.MessageQueue.QueueConsumer <valueType> messageQueue, Action <valueType> onMessage, ConsumerConfig config, AutoCSer.Log.ILog log = null) : base(messageQueue, config, log)
 {
     if (onMessage == null)
     {
         throw new ArgumentNullException();
     }
     this.onMessage = onMessage;
     setCheckSocketVersion();
 }
 /// <summary>
 /// TCP调用客户端
 /// </summary>
 /// <param name="attribute">TCP 调用服务器端配置信息</param>
 /// <param name="onCustomData">自定义数据包处理</param>
 /// <param name="log">日志接口</param>
 public TcpInternalClient(AutoCSer.Net.TcpInternalServer.ServerAttribute attribute = null, Action <SubArray <byte> > onCustomData = null, AutoCSer.Log.ILog log = null)
 {
     if (attribute == null)
     {
         attribute = AutoCSer.Net.TcpInternalServer.ServerAttribute.GetConfig("AutoCSer.TestCase.Nuget.Server", typeof(AutoCSer.TestCase.Nuget.Server));
     }
     _TcpClient_ = new AutoCSer.Net.TcpInternalServer.Client <TcpInternalClient>(this, attribute, onCustomData, log);
     if (attribute.IsAuto)
     {
         _TcpClient_.TryCreateSocket();
     }
 }
 /// <summary>
 /// AutoCSer.TestCase.Nuget.Server TCP调用服务端
 /// </summary>
 /// <param name="attribute">TCP 调用服务器端配置信息</param>
 /// <param name="verify">套接字验证委托</param>
 /// <param name="onCustomData">自定义数据包处理</param>
 /// <param name="log">日志接口</param>
 public TcpInternalServer(AutoCSer.Net.TcpInternalServer.ServerAttribute attribute = null, Func <System.Net.Sockets.Socket, bool> verify = null, Action <SubArray <byte> > onCustomData = null, AutoCSer.Log.ILog log = null)
     : base(attribute ?? (attribute = AutoCSer.Net.TcpInternalServer.ServerAttribute.GetConfig("AutoCSer.TestCase.Nuget.Server", typeof(AutoCSer.TestCase.Nuget.Server))), verify, null, 0, onCustomData, log, 0, false, false)
 {
     Value = new AutoCSer.TestCase.Nuget.Server();
     setCommandData(1);
     setCommand(0);
     if (attribute.IsAutoServer)
     {
         Start();
     }
 }
Exemplo n.º 14
0
 /// <summary>
 /// TCP调用客户端
 /// </summary>
 /// <param name="attribute">TCP 调用服务器端配置信息</param>
 #region IF IsVerifyMethod
 /// <param name="verifyMethod">TCP 验证方法</param>
 #endregion IF IsVerifyMethod
 /// <param name="log">日志接口</param>
 public TcpInternalSimpleClient(AutoCSer.Net.TcpInternalSimpleServer.ServerAttribute attribute = null /*IF:IsVerifyMethod*/, Func <TcpInternalSimpleClient, bool> verifyMethod = null /*IF:IsVerifyMethod*/, AutoCSer.Log.ILog log = null)
 {
     if (attribute == null)
     {
         #region IF IsServerCode
         attribute = AutoCSer.Net.TcpInternalSimpleServer.ServerAttribute.GetConfig("@ServerRegisterName", typeof(@Type.FullName));
         #endregion IF IsServerCode
         #region NOT IsServerCode
         attribute = AutoCSer.Config.Loader.Get <AutoCSer.Net.TcpInternalSimpleServer.ServerAttribute>("@ServerRegisterName") ?? _DefaultServerAttribute_;
         if (attribute.Name == null)
         {
             attribute.Name = "@ServerRegisterName";
         }
         #endregion NOT IsServerCode
     }
     _TcpClient_ = new AutoCSer.Net.TcpInternalSimpleServer.Client <TcpInternalSimpleClient>(this, attribute, log /*IF:IsVerifyMethod*/, verifyMethod /*IF:IsTimeVerify*/ ?? (Func <TcpInternalSimpleClient, bool>)_timerVerify_ /*IF:IsTimeVerify*//*IF:IsVerifyMethod*/);
     if (attribute.IsAuto)
     {
         _TcpClient_.TryCreateSocket();
     }
 }
 /// <summary>
 /// TCP调用客户端
 /// </summary>
 /// <param name="attribute">TCP调用服务器端配置信息</param>
 /// <param name="log">日志接口</param>
 public TcpOpenSimpleClient(AutoCSer.Net.TcpOpenSimpleServer.ServerAttribute attribute = null, AutoCSer.Log.ILog log = null)
 {
     if (attribute == null)
     {
         attribute = AutoCSer.Net.TcpOpenSimpleServer.ServerAttribute.GetConfig("AutoCSer.TestCase.TcpOpenSimpleServerPerformance.OpenSimpleServer", typeof(AutoCSer.TestCase.TcpOpenSimpleServerPerformance.OpenSimpleServer));
     }
     _TcpClient_ = new AutoCSer.Net.TcpOpenSimpleServer.Client <TcpOpenSimpleClient>(this, attribute, log);
     if (attribute.IsAutoClient)
     {
         _TcpClient_.TryCreateSocket();
     }
 }
Exemplo n.º 16
0
 /// <summary>
 /// @ServerRegisterName TCP调用服务端
 /// </summary>
 /// <param name="attribute">TCP 调用服务器端配置信息</param>
 /// <param name="verify">套接字验证委托</param>
 #region IF Type.Type.IsPublic
 /// <param name="value">TCP 服务目标对象</param>
 #endregion IF Type.Type.IsPublic
 /// <param name="log">日志接口</param>
 public TcpInternalSimpleServer(AutoCSer.Net.TcpInternalSimpleServer.ServerAttribute attribute = null, Func <System.Net.Sockets.Socket, bool> verify = null /*IF:Type.Type.IsPublic*/, @Type.FullName value = null /*IF:Type.Type.IsPublic*/, AutoCSer.Log.ILog log = null)
     : base(attribute ?? (attribute = AutoCSer.Net.TcpInternalSimpleServer.ServerAttribute.GetConfig("@ServerRegisterName", typeof(@Type.FullName))), verify, log, @IsCallQueue)
 {
     Value = /*IF:Type.Type.IsPublic*/ value ?? /*IF:Type.Type.IsPublic*/ new @Type.FullName();
     setCommandData(@MethodIndexs.Length);
     #region LOOP MethodIndexs
     #region NOT IsNullMethod
     #region IF IsVerifyMethod
     setVerifyCommand(@MethodIndex);
     #endregion IF IsVerifyMethod
     #region NOT IsVerifyMethod
     setCommand(@MethodIndex);
     #endregion NOT IsVerifyMethod
     #endregion NOT IsNullMethod
     #endregion LOOP MethodIndexs
     #region IF IsSetTcpServer
     Value.SetTcpServer(this);
     #endregion IF IsSetTcpServer
     if (attribute.IsAutoServer)
     {
         Start();
     }
 }
Exemplo n.º 17
0
 /// <summary>
 /// TCP调用客户端
 /// </summary>
 /// <param name="attribute">TCP调用服务器端配置信息</param>
 /// <param name="clientRoute">TCP 客户端路由</param>
 /// <param name="log">日志接口</param>
 public TcpOpenStreamClient(AutoCSer.Net.TcpOpenStreamServer.ServerAttribute attribute = null, AutoCSer.Net.TcpServer.ClientLoadRoute <AutoCSer.Net.TcpOpenStreamServer.ClientSocketSender> clientRoute = null, AutoCSer.Log.ILog log = null)
 {
     if (attribute == null)
     {
         attribute = AutoCSer.Net.TcpOpenStreamServer.ServerAttribute.GetConfig("AutoCSer.TestCase.TcpOpenStreamServerPerformance.OpenStreamServer", typeof(AutoCSer.TestCase.TcpOpenStreamServerPerformance.OpenStreamServer));
     }
     _TcpClient_ = new AutoCSer.Net.TcpOpenStreamServer.Client <TcpOpenStreamClient>(this, attribute, log, clientRoute);
     if (attribute.IsAutoClient)
     {
         _TcpClient_.TryCreateSocket();
     }
 }
 /// <summary>
 /// AutoCSer.TestCase.ChatServer.Server TCP调用服务端
 /// </summary>
 /// <param name="attribute">TCP调用服务器端配置信息</param>
 /// <param name="value">TCP服务目标对象</param>
 /// <param name="log">日志接口</param>
 /// <param name="onCustomData">自定义数据包处理</param>
 public TcpOpenServer(AutoCSer.Net.TcpOpenServer.ServerAttribute attribute = null, Func <System.Net.Sockets.Socket, bool> verify = null, AutoCSer.TestCase.ChatServer.Server value = null, Action <SubArray <byte> > onCustomData = null, AutoCSer.Log.ILog log = null)
     : base(attribute ?? (attribute = AutoCSer.Net.TcpOpenServer.ServerAttribute.GetConfig("AutoCSer.TestCase.ChatServer.Server", typeof(AutoCSer.TestCase.ChatServer.Server))), verify, onCustomData, log, false)
 {
     Value = value ?? new AutoCSer.TestCase.ChatServer.Server();
     setCommandData(5);
     setCommand(0);
     setCommand(1);
     setVerifyCommand(2);
     setCommand(3);
     setCommand(4);
     if (attribute.IsAutoServer)
     {
         Start();
     }
 }
Exemplo n.º 19
0
 /// <summary>
 /// 消息分发 客户端消费者
 /// </summary>
 /// <param name="node">消息分发节点</param>
 /// <param name="onMessage">消息处理委托,直接在 Socket 接收数据的 IO 线程中处理以避免线程调度,适应于快速结束的非阻塞函数;需要知道的是这种模式下如果产生阻塞会造成 Socket 停止接收数据甚至死锁</param>
 /// <param name="config">消息分发 读取配置</param>
 /// <param name="log">日志处理</param>
 public DistributionConsumerStream(DataStructure.MessageQueue.Distributor <valueType> node, Action <valueType> onMessage, DistributionConsumerConfig config, AutoCSer.Log.ILog log = null) : base(node, config, log)
 {
     if (onMessage == null)
     {
         throw new ArgumentNullException();
     }
     this.onMessage = onMessage;
     setCheckSocketVersion(onClientSocket);
 }