예제 #1
0
 public void Init()
 {
     TestRuntime.AssertXcodeVersion(11, 0);
     // connect so that we can later when the report and test with it
     connectedEvent = new AutoResetEvent(false);
     reportEvent    = new AutoResetEvent(false);
     host           = NetworkResources.MicrosoftUri.Host;
     // we create a connection which we are going to use to get the availabe
     // interfaces, that way we can later test protperties of the NWParameters class.
     using (var parameters = NWParameters.CreateUdp())
         using (var endpoint = NWEndpoint.Create(host, "80"))
         {
             using (var protocolStack = parameters.ProtocolStack) {
                 var ipOptions = protocolStack.InternetProtocol;
                 ipOptions.IPSetVersion(NWIPVersion.Version4);
             }
             connection = new NWConnection(endpoint, parameters);
             connection.SetQueue(DispatchQueue.DefaultGlobalQueue);              // important, else we will get blocked
             connection.SetStateChangeHandler(ConnectionStateHandler);
             connection.Start();
             Assert.True(connectedEvent.WaitOne(20000), "Connection timed out.");
             connection.GetEstablishmentReport(DispatchQueue.DefaultGlobalQueue, (r) => {
                 report = r;
                 reportEvent.Set();
             });
             Assert.True(reportEvent.WaitOne(20000), "Connection timed out.");
         }
 }