private static int GetSrcPort(ClientArguments arguments) { var srcPort = arguments.SourcePort; if (srcPort < IPEndPoint.MinPort) { srcPort = Random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort); } return(srcPort); }
/// <summary> /// Runs the test client with the given <paramref name="arguments"/>. /// </summary> /// <param name="arguments">The arguments to configure the <see cref="TestClient"/>.</param> /// <returns>A <see cref="Task"/> that represents the asynchronous run operation.</returns> public static async Task RunAsync(ClientArguments arguments) { var srcPort = GetSrcPort(arguments); var srcEndpoint = new IPEndPoint(IPAddress.Loopback, srcPort); var descEndpoint = new IPEndPoint(IPAddress.Loopback, arguments.DestinationPort); if (arguments.Mode == ProtocolType.Tcp) { await CommunicateOverTcp(srcEndpoint, descEndpoint).ConfigureAwait(false); } if (arguments.Mode == ProtocolType.Udp) { await CommunicateOverUdp(srcEndpoint, descEndpoint).ConfigureAwait(false); } }