static async Task Main(string[] args) { Encoding Utf8Encoding = new UTF8Encoding(); var pipelineFilter = new CommandLinePipelineFilter { Decoder = new DefaultStringPackageDecoder() }; IEasyClient <StringPackageInfo> client = new EasyClient <StringPackageInfo>(pipelineFilter); StringPackageInfo package = null; client.PackageHandler += async(s, p) => { package = p; if (string.IsNullOrWhiteSpace(p.Key)) { Console.WriteLine("unexpected result ---------"); } else { Console.WriteLine(p.Key); } await Task.CompletedTask; }; var connected = await client.ConnectAsync(new IPEndPoint(IPAddress.Loopback, 8899)); Console.WriteLine(connected); client.StartReceive(); byte[] bytes1 = Utf8Encoding.GetBytes(new char[] { (char)0x00, (char)0x00, (char)0x01, (char)0x61 }); byte[] bytes2 = Utf8Encoding.GetBytes(new char[] { (char)0x00, (char)0x00, (char)0x01, (char)0x61, (char)0x62 }); byte[] bytes3 = Utf8Encoding.GetBytes(new char[] { (char)0x00, (char)0x00, (char)0x01, (char)0x61 }); byte[] bytes4 = Utf8Encoding.GetBytes(new char[] { (char)0x00, (char)0x00, (char)0x01, (char)0x61 }); await client.SendAsync(bytes1); //expected result: a, true result: a await Task.Delay(1000); await client.SendAsync(bytes2); //expected result: a, true result: a await Task.Delay(1000); await client.SendAsync(bytes3); //expected result: a, true result: null await Task.Delay(1000); await client.SendAsync(bytes4); //expected result: a, tree result: null await Task.Delay(1000); await client.CloseAsync(); }
static async Task Test3() { MyBeginEndMarkPipelineFilter filter = new MyBeginEndMarkPipelineFilter(); var client = new EasyClient <StringPackageInfo>(filter).AsClient(); if (!await client.ConnectAsync(new IPEndPoint(IPAddress.Loopback, 6001))) { Console.WriteLine("Failed to connect the target server."); return; } client.PackageHandler += Client_PackageHandler; int i = 0; do { string msg = @"MSH|^~\&|HIS|LIS|ABC|DEF|20200408143100|pv1|ADT^A08|A6B64388-1F8B-4763-BA4D-B4A76BE58DA9|P|2.4|||||CHN EVN|A08|20200408143100 PID|1|415320^^^&PATID|415320^^^&PATID~1221284^^^&BLH~800033^^^&BRKH^BLH~0^^^&YEXH||CESHI||19900408000000|M||||||||M^已婚||||||17^汉族||||||40^中国 NK1||CESHI|SEL^SEL PV1|1|I|4011^急诊外科^29^^^^1001^急诊外科病区||||6371^张三||||||1|||||||2001~现金||||||||||||||||||||1|||||||||| "; string d1 = Encoding.UTF8.GetString(filter.BeginMark.ToArray()); string d2 = Encoding.UTF8.GetString(filter.EndMark.ToArray()); msg = d1 + msg + d2; byte[] bytes = Encoding.UTF8.GetBytes(msg); try { await client.SendAsync(new ReadOnlyMemory <byte>(bytes)); client.StartReceive(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } while (i++ < 2); }