public SocketServer(ITestOutputHelper output, IPAddress address, bool dualMode, out int port)
{
_output = output;
if (dualMode)
{
_server = new Socket(SocketType.Stream, ProtocolType.Tcp);
}
else
{
_server = new Socket(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
}
port = _server.BindToAnonymousPort(address);
_server.Listen(1);
IPAddress remoteAddress = address.AddressFamily == AddressFamily.InterNetwork ? IPAddress.Any : IPAddress.IPv6Any;
EndPoint remote = new IPEndPoint(remoteAddress, 0);
SocketAsyncEventArgs e = new SocketAsyncEventArgs();
e.RemoteEndPoint = remote;
e.Completed += new EventHandler<SocketAsyncEventArgs>(Accepted);
e.UserToken = _waitHandle;
_server.AcceptAsync(e);
}