/// <summary> /// TCP调用客户端 /// </summary> /// <param name="attribute">TCP调用服务器端配置信息</param> /// <param name="onCustomData">自定义数据包处理</param> /// <param name="log">日志接口</param> public TcpOpenClient(AutoCSer.Net.TcpOpenServer.ServerAttribute attribute = null, Action <SubArray <byte> > onCustomData = null, AutoCSer.Log.ILog log = null) { if (attribute == null) { attribute = AutoCSer.Net.TcpOpenServer.ServerAttribute.GetConfig("AutoCSer.TestCase.TcpOpenServerPerformance.OpenServer", typeof(AutoCSer.TestCase.TcpOpenServerPerformance.OpenServer)); } _TcpClient_ = new AutoCSer.Net.TcpOpenServer.Client <TcpOpenClient>(this, attribute, onCustomData, log); if (attribute.IsAutoClient) { _TcpClient_.TryCreateSocket(); } }
/// <summary> /// TCP调用客户端 /// </summary> /// <param name="attribute">TCP调用服务器端配置信息</param> /// <param name="verifyMethod">TCP验证方法</param> /// <param name="onCustomData">自定义数据包处理</param> /// <param name="log">日志接口</param> public TcpOpenClient(AutoCSer.Net.TcpOpenServer.ServerAttribute attribute = null, Func <TcpOpenClient, AutoCSer.Net.TcpOpenServer.ClientSocketSender, bool> verifyMethod = null, Action <SubArray <byte> > onCustomData = null, AutoCSer.Log.ILog log = null) { if (attribute == null) { attribute = AutoCSer.Config.Loader.Get <AutoCSer.Net.TcpOpenServer.ServerAttribute>("AutoCSer.TestCase.ChatServer.Server") ?? AutoCSer.Json.Parser.Parse <AutoCSer.Net.TcpOpenServer.ServerAttribute>(@"{""CheckSeconds"":59,""ClientOutputSleep"":0,""ClientSegmentationCopyPath"":""..\\..\\..\\ChatClient\\"",""ClientSendBufferMaxSize"":0x100000,""ClientTryCreateSleep"":1000,""CommandPoolBitSize"":0x03,""GenericType"":null,""Host"":""127.0.0.1"",""IsAttribute"":true,""IsAutoClient"":true,""IsAutoServer"":true,""IsBaseTypeAttribute"":false,""IsJsonSerialize"":true,""IsMarkData"":false,""IsSegmentation"":true,""IsServerBuildOutputThread"":false,""IsSimpleSerialize"":true,""MaxCustomDataSize"":0x3FF4,""MaxInputSize"":0x3FF4,""MaxVerifyDataSize"":1024,""MemberFilters"":""Instance"",""MinCompressSize"":0,""Name"":null,""Port"":0x3070,""ReceiveBufferSize"":""Kilobyte"",""ReceiveVerifyCommandSeconds"":9,""SendBufferSize"":""Kilobyte"",""ServerOutputSleep"":1,""ServerSendBufferMaxSize"":0,""VerifyString"":null,""TypeId"":{}}"); if (attribute.Name == null) { attribute.Name = "AutoCSer.TestCase.ChatServer.Server"; } } _TcpClient_ = new AutoCSer.Net.TcpOpenServer.Client <TcpOpenClient>(this, attribute, onCustomData, log, verifyMethod); if (attribute.IsAutoClient) { _TcpClient_.TryCreateSocket(); } }
/// <summary> /// 时间验证客户端验证 /// </summary> /// <param name="verify">时间验证服务客户端委托</param> /// <param name="sender"></param> /// <param name="client"></param> /// <returns></returns> public unsafe static bool Verify(Verifier verify, ClientSocketSender sender, AutoCSer.Net.TcpOpenServer.Client client) { long ticks; ServerAttribute attribute = client.Attribute; string verifyString = attribute.VerifyString; if (verifyString == null) { ticks = 0; return(verify(sender, 0, null, ref ticks).Value); } ulong markData = 0; if (attribute.IsMarkData) { markData = attribute.VerifyHashCode; } ticks = Date.NowTime.SetUtc().Ticks; TcpServer.ClientSocketBase socket = sender.ClientSocket; do { ulong randomPrefix = Random.Default.SecureNextULongNotZero(); while (randomPrefix == markData) { randomPrefix = Random.Default.SecureNextULongNotZero(); } socket.ReceiveMarkData = attribute.IsMarkData ? markData ^ randomPrefix : 0UL; sender.SendMarkData = 0; long lastTicks = ticks; TcpServer.ReturnValue <bool> isVerify = verify(sender, randomPrefix, TcpServer.TimeVerifyServer.Md5(verifyString, randomPrefix, ticks), ref ticks); if (isVerify.Value) { sender.SendMarkData = socket.ReceiveMarkData; return(true); } if (isVerify.Type != TcpServer.ReturnType.Success || ticks <= lastTicks) { socket.Log.Add(AutoCSer.Log.LogType.Error, "TCP客户端验证失败 [" + isVerify.Type.ToString() + "] " + ticks.toString() + " <= " + lastTicks.toString()); return(false); } socket.Log.Add(AutoCSer.Log.LogType.Error, "TCP客户端验证时间失败重试 " + ticks.toString() + " - " + lastTicks.toString()); }while (true); }
public Server(ServerAttribute attribute, Func <System.Net.Sockets.Socket, bool> verify, AutoCSer.Net.TcpServer.IServerCallQueueSet serverCallQueue, byte extendCommandBits, Action <SubArray <byte> > onCustomData, ILog log, int callQueueCount, bool isCallQueueLink, bool isSynchronousVerifyMethod) : base(attribute, verify, serverCallQueue, extendCommandBits, onCustomData, log, AutoCSer.Threading.ThreadTaskType.TcpOpenServerGetSocket, callQueueCount, isCallQueueLink, isSynchronousVerifyMethod) { }
/// <summary> /// TCP 开放服务客户端 /// </summary> /// <param name="attribute">TCP服务调用配置</param> /// <param name="maxTimeoutSeconds">最大超时秒数</param> /// <param name="onCustomData">自定义数据包处理</param> /// <param name="log">日志接口</param> /// <param name="clientRoute">TCP 客户端路由</param> internal Client(ServerAttribute attribute, ushort maxTimeoutSeconds, Action <SubArray <byte> > onCustomData, ILog log, AutoCSer.Net.TcpServer.ClientLoadRoute <ClientSocketSender> clientRoute) : base(attribute, maxTimeoutSeconds, onCustomData, log) { this.clientRoute = clientRoute; }