private static async Task StartServer(NetSocketFactory factory, EndPoint endPoint) { var server = factory.Listen(endPoint); while (true) { var client = await server.Accept(); StartClientTask(client); } }
private static async Task StartClient(NetSocketFactory factory, EndPoint endPoint) { using (var client = await factory.Connect(endPoint)) { var producer = client.Stream.AsIntLengthPrefixedProducer(); for (var i = 0; i < 100; i++) { await producer.Add(GenerateBuffer(i)); } await client.Disconnect(); } }
private static async Task StartClient(NetSocketFactory factory, EndPoint endPoint) { using (var client = await factory.Connect(endPoint)) { var producer = client.Stream.AsIntLengthPrefixedProducer(); for (var i = 0; i < 100; i++) { await producer.Add(new ArraySegment<byte>(GenerateBuffer(i))); } await client.Disconnect(); } }
public static async void Work() { var factory = new NetSocketFactory(); var endPoint = new IPEndPoint(IPAddress.Loopback, 3232); var tasks = new List <Task> { StartServer(factory, endPoint), StartClient(factory, endPoint), StartClient(factory, endPoint), StartClient(factory, endPoint), }; await Task.WhenAll(tasks); }
private static async void Work() { var factory = new NetSocketFactory(); var endPoint = new IPEndPoint(IPAddress.Loopback, 3232); var tasks = new List<Task> { StartServer(factory, endPoint), StartClient(factory, endPoint), StartClient(factory, endPoint), StartClient(factory, endPoint), }; await Task.WhenAll(tasks); }