public async Task TestAsync4() { TcpRemote remote = new TcpRemote(); var res = await remote.SendAsync <TestPacket1>(null); res.ToString(); await Task.Delay(10); res.ToString(); }
private static async void NewRemote(int clientIndex) { IRemote remote = new TcpRemote() { }; remote.OnReceiveCallback += receiver.TestReceive; var res = await remote.ConnectAsync(new IPEndPoint(IPAddress.Loopback, 54321)); if (res == null) { Console.WriteLine($"Remote{clientIndex}:Success"); } else { throw res; } await TestRpc(clientIndex, remote); Stopwatch look1 = new Stopwatch(); var msg = new TestPacket1 { Value = 0 }; look1.Start(); await Task.Run(() => { for (int i = 0; i < MessageCount; i++) { //Console.WriteLine($"Remote{clientIndex}:发送{nameof(Packet1)}=={i}"); msg.Value = i; remote.SendAsync(msg); } }); look1.Stop(); Console.WriteLine($"Remote{clientIndex}: SendAsync{MessageCount}包 ------ 发送总时间: {look1.ElapsedMilliseconds}----- 平均每秒发送:{MessageCount * 1000 / (look1.ElapsedMilliseconds + 1)}"); //Remote.BroadCastAsync(new Packet1 { Value = -99999 },remote); //var (Result, Excption) = await remote.SendAsync<Packet2>(new Packet1 { Value = 100 }); //Console.WriteLine($"RPC接收消息{nameof(Packet2)}--{Result.Value}"); }