private void DualModeBeginSendTo_EndPointToHost_Helper(IPAddress connectTo, IPAddress listenOn, bool dualModeServer, bool expectedToTimeout = false)
{
int port;
Socket client = new Socket(SocketType.Dgram, ProtocolType.Udp);
using (SocketUdpServer server = new SocketUdpServer(_log, listenOn, dualModeServer, out port))
{
// Send a few packets, in case they aren't delivered reliably.
for (int i = 0; i < (expectedToTimeout ? 1 : TestSettings.UDPRedundancy); i++)
{
IAsyncResult async = client.BeginSendTo(new byte[1], 0, 1, SocketFlags.None, new IPEndPoint(connectTo, port), null, null);
int sent = client.EndSendTo(async);
Assert.Equal(1, sent);
}
bool success = server.WaitHandle.WaitOne(expectedToTimeout ? TestSettings.FailingTestTimeout : TestSettings.PassingTestTimeout); // Make sure the bytes were received
if (!success)
{
throw new TimeoutException();
}
}
}