public CloudClient(IContainer container) { SyncWaitDic = new ConcurrentDictionary <long, ReturnEventWaitHandle>(10, 10000); AsyncCallDiy = new ConcurrentDictionary <long, AsyncCalls>(); CallBackDiy = new ConcurrentDictionary <long, AsyncCalls>(); AsyncRunDiy = new ConcurrentDictionary <long, AsyncRun>(); AsyncWaitTimeOut = new List <KeyValuePair <long, DateTime> >(); FodyDir = new Dictionary <Type, Type>(); ClientManager = container.Resolve <IConnectionManager>(); ClientManager.BinaryInput += DataOn; ClientManager.Disconnect += p => Disconnect?.Invoke(p); MillisecondsTimeout = container.Resolve <TimeOutOptions>().MillisecondsTimeout; IsCheckAsyncTimeOut = container.Resolve <TimeOutOptions>().IsCheckAsyncTimeOut; Sync = new ZYSync() { SyncSend = SendData, SyncSendAsWait = SendDataAsWait }; Module = container.Resolve <IModuleDictionary>(); IsClose = false; LoggerFactory = container.Resolve <ILoggerFactory>(); Log = new DefaultLog(LoggerFactory.CreateLogger <CloudClient>()); Task.Run(new Action(CheckAsyncTimeOut)); }
static void Main(string[] args) { LogAction.LogOut += LogAction_LogOut; CloudClient client = new CloudClient(new SocketClient(), 500000, 1024 * 1024); //最大数据包能够接收 1M PackHander tmp = new PackHander(); client.Install(tmp); client.Disconnect += Client_Disconnect; if (client.Connect("127.0.0.1", 2285)) { ZYSync Sync = client.Sync; var res = Sync.CR(1000, "AAA", "BBB")?[0]?.Value <bool>(); if (res != null && res == true) { var html = Sync.CR(2001, "http://www.baidu.com")?[0]?.Value <string>(); if (html != null) { Console.WriteLine("BaiduHtml:" + html.Length); var time = Sync.CR(2002)?.First?.Value <DateTime>(); Console.WriteLine("ServerTime:" + time); Sync.CV(2003, "123123"); var x = Sync.CR(2001, "http://www.qq.com"); Console.WriteLine("QQHtml:" + x.First.Value <string>().Length); var recx = Sync.CR(2500, 100)?.First?.Value <int>(); System.Diagnostics.Stopwatch stop = new System.Diagnostics.Stopwatch(); stop.Start(); var rec = Sync.CR(2500, 10000)?.First?.Value <int>(); stop.Stop(); if (rec != null) { Console.WriteLine("Rec:{0} time:{1} MS", rec.Value, stop.ElapsedMilliseconds); } RunTest(client); } } Console.WriteLine("Close"); Console.ReadLine(); } }
public CloudClient(ISyncClient client, int millisecondsTimeout, int maxBufferLength) { SyncWaitDic = new ConcurrentDictionary <long, ReturnEventWaitHandle>(10, 10000); AsyncCallDiy = new ConcurrentDictionary <long, AsyncCalls>(); CallBackDiy = new ConcurrentDictionary <long, AsyncCalls>(); AsyncRunDiy = new ConcurrentDictionary <long, AsyncRun>(); Client = client; MillisecondsTimeout = millisecondsTimeout; RingBuffer = new ZYNetRingBufferPool(maxBufferLength); Sync = new ZYSync(); Sync.SyncSend = SendData; Sync.SyncSendAsWait = SendDataAsWait; Module = new ModuleDictionary(); }
static void Main(string[] args) { Console.OutputEncoding = System.Text.Encoding.UTF8; LogAction.LogOut += LogAction_LogOut; CloudClient client = new CloudClient(new SocketClient(), 500000, 1024 * 1024); //最大数据包能够接收 1M PackHander tmp = new PackHander(); client.Install(tmp); client.Disconnect += Client_Disconnect; if (client.Connect("127.0.0.1", 2285)) { ZYSync Sync = client.Sync; IPacker ServerPack = Sync.Get <IPacker>(); var res = ServerPack.IsLogOn("AAA", "BBB")?[0]?.Value <bool>(); if (res != null && res == true) { var html = ServerPack.StartDown("http://www.baidu.com")?[0]?.Value <string>(); if (html != null) { Console.WriteLine("BaiduHtml:" + html.Length); var time = ServerPack.GetTime(); Console.WriteLine("ServerTime:" + time); ServerPack.SetPassWord("123123"); var x = ServerPack.StartDown("http://www.qq.com"); Console.WriteLine("QQHtml:" + x.First.Value <string>().Length); System.Diagnostics.Stopwatch stop = new System.Diagnostics.Stopwatch(); stop.Start(); var rec = ServerPack.TestRec2(1000); stop.Stop(); Console.WriteLine("Rec:{0} time:{1} MS", rec, stop.ElapsedMilliseconds); TestRun(client); } } Console.WriteLine("Close"); Console.ReadLine(); } }
public static string SendMsgToUser(this ZYSync sync, string account, string msg) { return(sync.CR((int)Cmdtype.SendTo, account, msg)?.First?.Value <string>()); }
public static void SendMessageToAllUser(this ZYSync sync, string msg) { sync.CV((int)Cmdtype.SendAll, msg); }
/// <summary> /// 登入 /// </summary> /// <param name="sync"></param> /// <param name="username"></param> /// <returns></returns> public static ReturnResult LogOn(this ZYSync sync, string username) { return(sync.CR((int)Cmdtype.LogOn, username)); }