/// <summary>粘包测试</summary> public static void Test() { var svr = new NetServer(); svr.Port = 777; svr.SessionPacket = new HeaderLengthPacketFactory(); svr.Log = Log.XTrace.Log; svr.LogReceive = true; svr.Start(); // 凑齐10个带有长度的数据帧一起发出 var ms = new MemoryStream(); for (int i = 0; i < 5; i++) { var size = i < 4 ? Security.Rand.Next(1400) : Security.Rand.Next(2000, 30000); var str = Security.Rand.NextString(size); var s = str.Substring(0, Math.Min(str.Length, 16)); //var h = str.GetBytes().ToHex(); var mm = new MemoryStream(); mm.WriteArray(str.GetBytes()); var h = mm.ToArray().ToHex(); h = h.Substring(0, Math.Min(h.Length, 32)); Console.WriteLine("{0}\t{1}\t{2}", mm.ToArray().Length, s, h); ms.WriteArray(str.GetBytes()); } var client = new NetUri("tcp://127.0.0.1:777").CreateRemote(); //client.Remote.Address = NetHelper.MyIP(); //client.Remote.Address = System.Net.IPAddress.Parse("1.0.0.13"); client.Log = Log.XTrace.Log; client.LogSend = true; //client.BufferSize = 1500; client.SendAsync(ms.ToArray()); Console.ReadKey(true); client.Close(); svr.Dispose(); }