public void SendMessageNoSure(Message msg, EndPoint endpoint) { var bytes = EntityBufCore.Serialize(msg); var segments = SplitBytes(bytes, _max_package_len).ToArray(); for (var i = 0; i < segments.Length; i++) { var segment = segments[i]; _udpClient.Send(segment, segment.Length); } }
internal T DoRequest <T>(int funcid, object param) { SOARedirectRequest request = new SOARedirectRequest(); request.FuncId = funcid; if (param == null) { request.Param = null; } else { request.Param = EntityBufCore.Serialize(param); } Message msg = new Message((int)SOAMessageType.DoSOARedirectRequest); msg.MessageHeader.TransactionID = SocketApplicationComm.GetSeqNum(); msg.MessageBuffer = EntityBufCore.Serialize(request); try { var resp = SendMessageAnsy <SOARedirectResponse>(msg, timeOut: 5000); if (TimeOutTimes > 0) { TimeOutTimes--; } if (resp.IsSuccess) { return(EntityBuf.EntityBufCore.DeSerialize <T>(resp.Result)); } else { throw new Exception(resp.ErrMsg); } } catch (TimeoutException ex) { TimeOutTimes++; if (TimeOutTimes > MAXTIMEOUTTIMES) { OnError(new System.Net.WebException("一段时间内连续超时,可能出现网络问题")); } throw ex; } }
internal T DoRequest <T>(int funcid, object param) { SOARedirectRequest request = new SOARedirectRequest(); request.FuncId = funcid; if (param == null) { request.Param = null; } else { request.Param = EntityBufCore.Serialize(param); } Message msg = new Message((int)SOAMessageType.DoSOARedirectRequest); msg.MessageHeader.TransactionID = SocketApplicationComm.GetSeqNum(); msg.MessageBuffer = EntityBufCore.Serialize(request); T result = SendMessageAnsy <T>(msg); return(result); }
public override bool SendMessage(Message msg, IPEndPoint endpoint) { try { var bytes = EntityBufCore.Serialize(msg); var segments = SplitBytes(bytes, _max_package_len).ToArray(); var bagid = GetBagId(segments.First()); int[] sended = segments.Select(p => 0).ToArray(); int trytimes = 0; Console.WriteLine("发消息:" + bagid + ",长度:" + bytes.Length); while (true) { lock (_udpClient.Client) { _sendmsgflag.BagId = bagid; _sendmsgflag.Reset(); for (var i = 0; i < segments.Length; i++) { if (sended[i] != 0) { continue; } var segment = segments[i]; _udpClient.Send(segment, segment.Length); sended[i] = 1; } Console.WriteLine("等待信号"); _sendmsgflag.Wait(1000); if (!_sendmsgflag.IsTimeOut) { //LogManager.LogHelper.Instance.Info("发消息:" + bagid + "成功"); return(true); } } if (trytimes++ >= TimeOutTryTimes) { //LogManager.LogHelper.Instance.Info("发消息:" + bagid + "超时,重试次数:" + trytimes); throw new TimeoutException(); } //LogManager.LogHelper.Instance.Info("发消息:" + bagid + "需要重试,请求重发包"); var revmsg = QuestionBag(bagid, endpoint); if (revmsg.IsReved) { //LogManager.LogHelper.Instance.Info("发消息:" + bagid + "请求重发包,返回完成"); return(true); } if (revmsg.Miss != null && revmsg.Miss.Length > 0) { //LogManager.LogHelper.Instance.Info("发消息:" + bagid + "请求重发包,返回缺少包数量:" + revmsg.Miss.Length); foreach (var i in revmsg.Miss) { sended[i] = 0; } } else if (revmsg.Miss == null) { //LogManager.LogHelper.Instance.Info("发消息:" + bagid + "请求重发包,返回完全没收到"); for (int i = 0; i < sended.Length; i++) { sended[i] = 0; } } } } catch (Exception ex) { OnError(ex); return(false); } }
static void Main2(string[] args) { var request = new LJC.FrameWork.Comm.HttpRequestEx(); request.SupportCompression = true; var response = request.DoRequest("http://jingzhi.funds.hexun.com/jz/", null); List <string> list = new List <string>(); var tpp = list.GetType(); Dictionary <int, string> dics = new Dictionary <int, string>(); dics.Add(1, "ljc"); dics.Add(2, "cc"); Type tp = dics.GetType(); TestClass test = new TestClass(); test.col1 = 1234; test.DateCol = DateTime.Now; test.LongCol = 234456788; test.flag = EntityBufTypeFlag.TestFlag | EntityBufTypeFlag.ArrayFlag; test.flags = new EntityBufTypeFlag[] { EntityBufTypeFlag.ArrayFlag, EntityBufTypeFlag.TestFlag, EntityBufTypeFlag.ThreeFlag, }; test.IntArray = new int[] { 1000, 200, 122 }; test.List = new List <Test2Class>(); test.List.Add(new Test2Class { Boo = false, xx = 1, }); test.List.Add(new Test2Class { Boo = true, xx = 22, }); test.List.Add(new Test2Class { Boo = false, xx = 1200, }); test.Dic = new Dictionary <int, string>(); test.Dic.Add(1, "xxxx"); test.Dic.Add(2, "haha"); test.Dic2 = new Dictionary <int, Test2Class>(); test.Dic2.Add(1, new Test2Class { Boo = true, xx = 2 }); test.Dic2.Add(2, new Test2Class { Boo = true, xx = 3 }); var dic3item = new Dictionary <string, Test2Class>(); dic3item.Add("1", new Test2Class { Boo = true, xx = 10998 }); dic3item.Add("2", new Test2Class { Boo = false, xx = 2558, }); test.Dic3 = new Dictionary <int, Dictionary <string, Test2Class> >(); test.Dic3.Add(1, dic3item); test.Dic3.Add(2, dic3item); test.DateColArray = new DateTime[] { new DateTime(1990, 1, 1, 0, 1, 1), new DateTime(1991, 1, 1, 0, 1, 1), new DateTime(1992, 1, 1, 0, 1, 1), new DateTime(1993, 1, 1, 0, 1, 1), }; test.BoolArray = new bool[] { false, false, true, true, false, true }; test.Test2 = new Test2Class { xx = 1111, Boo = true, }; test.longArray = new long[] { 1, 2, 3, 45 }; test.ListTest2 = new Test2Class[] { new Test2Class { xx = 1223, Boo = true, }, new Test2Class { xx = 998, Boo = false, }, new Test2Class { xx = 998, Boo = false, }, new Test2Class { xx = 998, Boo = false, }, new Test2Class { xx = 998, Boo = false, } , new Test2Class { xx = 998, Boo = false, }, new Test2Class { xx = 998, Boo = false, } , new Test2Class { xx = 998, Boo = false, }, new Test2Class { xx = 998, Boo = false, } , new Test2Class { xx = 998, Boo = false, }, new Test2Class { xx = 998, Boo = false, } , new Test2Class { xx = 998, Boo = false, }, new Test2Class { xx = 998, Boo = false, } , new Test2Class { xx = 998, Boo = false, }, new Test2Class { xx = 998, Boo = false, } , new Test2Class { xx = 998, Boo = false, }, new Test2Class { xx = 998, Boo = false, } , new Test2Class { xx = 998, Boo = false, }, new Test2Class { xx = 998, Boo = false, } , new Test2Class { xx = 998, Boo = false, }, new Test2Class { xx = 998, Boo = false, } , new Test2Class { xx = 998, Boo = false, }, new Test2Class { xx = 998, Boo = false, } , new Test2Class { xx = 998, Boo = false, }, new Test2Class { xx = 998, Boo = false, } , new Test2Class { xx = 998, Boo = false, }, new Test2Class { xx = 998, Boo = false, } , new Test2Class { xx = 998, Boo = false, }, new Test2Class { xx = 998, Boo = false, } , new Test2Class { xx = 998, Boo = false, }, new Test2Class { xx = 998, Boo = false, } , new Test2Class { xx = 998, Boo = false, }, new Test2Class { xx = 998, Boo = false, } , new Test2Class { xx = 998, Boo = false, }, new Test2Class { xx = 998, Boo = false, } , new Test2Class { xx = 998, Boo = false, }, new Test2Class { xx = 998, Boo = false, } , new Test2Class { xx = 998, Boo = false, }, new Test2Class { xx = 998, Boo = false, } , new Test2Class { xx = 998, Boo = false, }, new Test2Class { xx = 998, Boo = false, } , new Test2Class { xx = 998, Boo = false, }, new Test2Class { xx = 998, Boo = false, } , new Test2Class { xx = 998, Boo = false, }, new Test2Class { xx = 998, Boo = false, } , new Test2Class { xx = 998, Boo = false, } }; var innerDic = new Dictionary <int, string>(); innerDic.Add(1, "ljc"); innerDic.Add(2, "李大大象"); test.DicArray = new Dictionary <int, string>[] { innerDic }; System.Diagnostics.Stopwatch sp = new System.Diagnostics.Stopwatch(); sp.Restart(); long m1 = GC.GetTotalMemory(true); for (int i = 0; i < 1; i++) { string jsonstr = test.ToJson(); if (i == 0) { int len = Encoding.UTF8.GetBytes(jsonstr).Length; Console.WriteLine("JSON序列化包的大小:" + len + "字节"); } var fromjson = (TestClass)LJC.FrameWork.Comm.JsonHelper.JsonToEntity <TestClass>(jsonstr); } long m2 = GC.GetTotalMemory(true); sp.Stop(); Console.WriteLine("JSON序列化反序列化总共费时:" + sp.ElapsedMilliseconds); Console.WriteLine("共用内存:" + (m2 - m1).ToString()); sp.Restart(); long m3 = GC.GetTotalMemory(true); for (int i = 0; i < 100; i++) { var data = EntityBufCore.Serialize(test); if (i == 0) { Console.WriteLine("二进制序列化包的大小:" + data.Length + "字节"); } //MemoryStream ms2 = new MemoryStream(ms.GetBuffer()); //LJC.FrameWork.EntityBuf.MemoryStreamReader reader = new MemoryStreamReader(new BinaryReader(ms2)); object o = EntityBufCore.DeSerialize <TestClass>(data); } long m4 = GC.GetTotalMemory(true); sp.Stop(); Console.WriteLine("二进制序列化反序列化总共费时:" + sp.ElapsedMilliseconds); Console.WriteLine("共用内存:" + (m4 - m3).ToString()); sp.Restart(); long m5 = GC.GetTotalMemory(true); for (int i = 0; i < 0; i++) { string xml = LJC.FrameWork.Comm.SerializerHelper.SerializerToXML(test); if (i == 0) { int len = Encoding.UTF8.GetBytes(xml).Length; Console.WriteLine("xml序列化包大小:" + len + "字节"); } var xmlOjb = LJC.FrameWork.Comm.SerializerHelper.DeserializerXML <TestClass>(xml); } long m6 = GC.GetTotalMemory(true); sp.Stop(); Console.WriteLine("xml序列化反序列化总共费时:" + sp.ElapsedMilliseconds); Console.WriteLine("共用内存:" + (m6 - m5).ToString()); //byte bt = (byte)EntityBufTypeFlag.ThreeFlag; //PropertyInfo[] props = typeof(TestClass).GetProperties(); //foreach (PropertyInfo prop in props) //{ // string s = prop.ReflectedType.Name; //} //var result= LJC.FrameWork.Comm.CommFun.GetQuickDataBaseAttr<TestClass>(); //string filename=@"E:\程序\投资机器人(广发证券真实交易版)\ATrade_gx\ATUI2.0\ATradeUI2.0\bin\Debug\gfaccount\x.png"; //LJC.FrameWork.Comm.ImageHelper.SaveImage(null, ref filename, false); //string s=TT(p => p.col1); //var josn1 = "{\"error_info\":\"验证码输入不正确!\",\"success\":false}"; //var ss= JsonHelper.FormJson(josn1).EvalJson("error_info"); //var josn2 = "{\"total\":1,\"data\":[{\"pre_interest_tax\":\"0\",\"pre_fine\":\"0\",\"money_type\":\"0\",\"fetch_balance\":\"28562.30\",\"current_balance\":\"28562.30\",\"real_sell_balance\":\"0\",\"integral_balance\":\"1066933.58\",\"market_value\":\"5751.00\",\"correct_balance\":\"0\",\"money_type_dict\":\"人民币\",\"foregift_balance\":\"0\",\"fetch_balance_old\":\"0\",\"mortgage_balance\":\"0\",\"frozen_balance\":\"0\",\"pre_interest\":\"10.37\",\"interest\":\"0\",\"asset_balance\":\"34313.30\",\"enable_balance\":\"28562.30\",\"unfrozen_balance\":\"0\",\"fine_integral\":\"0\",\"fetch_cash\":\"28562.30\",\"opfund_market_value\":\"0\",\"real_buy_balance\":\"0\",\"entrust_buy_balance\":\"0\",\"rate_kind\":\"0\",\"fund_balance\":\"28562.30\",\"begin_balance\":\"28562.30\"}],\"success\":true}"; //var dj=JsonHelper.DynamicJson(josn2); //int total = dj.total; //var current_balance = dj.data[0]["current_balance"]; //var josn3 = "[{name:\"ljc\",age:29},{name:\"chenghong\",age:22}]"; //var dj3 = JsonHelper.DynamicJson(josn3); //var age2 = dj3[1]["age"]; }