/// <summary> /// Stops the currently running search or resolution. /// </summary> public void Stop() { if (resolveTimer != null) { resolveTimer.Dispose(); resolveTimer = null; } TeardownWatchSocket(registeredServiceHandle); if (registeredServiceHandle != IntPtr.Zero) { mDNSImports.DNSServiceRefDeallocate(registeredServiceHandle); registeredServiceHandle = IntPtr.Zero; } resolveReplyCb = null; registerReplyCb = null; TeardownWatchSocket(ipLookupQueryHandle); if (ipLookupQueryHandle != IntPtr.Zero) { mDNSImports.DNSServiceRefDeallocate(ipLookupQueryHandle); ipLookupQueryHandle = IntPtr.Zero; } ipLookupReplyCb = null; }
/// <summary> /// Stops the monitoring of TXT-record updates for the receiver. /// </summary> public void StopMonitoring() { TeardownWatchSocket(serviceQueryHandle); if (serviceQueryHandle != IntPtr.Zero) { mDNSImports.DNSServiceRefDeallocate(serviceQueryHandle); serviceQueryHandle = IntPtr.Zero; } queryReplyCb = null; }
// private IAsyncResult asyncResultsHostEntry; // private void AsyncGetHostEntryCallback(IAsyncResult result) // { // asyncResultsHostEntry = result; // NetService c = (NetService)result.AsyncState; // // // We invoke the GetHostEntryFinished method on the proper thread. // // This allows us to update internal variables, and invoke the delegate method // // on the same thread the user is using. // Invoke(new MethodInvoker(GetHostEntryFinished)); // } // // private void GetHostEntryFinished() // { // System.Net.IPHostEntry hostInfo = System.Net.Dns.EndGetHostEntry(asyncResultsHostEntry); // asyncResultsHostEntry = null; // // ArrayList endpoints = new ArrayList(); // // foreach (System.Net.IPAddress address in hostInfo.AddressList) // { // System.Net.IPEndPoint ep = new System.Net.IPEndPoint(address, mPort); // endpoints.Add(ep); // } // mAddresses = endpoints; // // if (DidResolveService != null) // DidResolveService(this); // } /// <summary> /// Starts the monitoring of TXT-record updates for the receiver. /// </summary> public void StartMonitoring() { // Ignore the method call if we're already monitoring the service // More than one objects may be informed of TXT-record updates via the delegates if (queryReplyCb == null) { queryReplyCb = new mDNSImports.DNSServiceQueryReply(QueryReply); String fqdn = String.Format("{0}.{1}{2}", Name, Type, Domain); DNSServiceErrorType err; err = mDNSImports.DNSServiceQueryRecord(out serviceQueryHandle, DNSServiceFlags.LongLivedQuery, 0, fqdn, DNSServiceType.TXT, DNSServiceClass.IN, queryReplyCb, IntPtr.Zero); if (err == DNSServiceErrorType.NoError) { SetupWatchSocket(serviceQueryHandle); } else { throw new DNSServiceException("DNSServiceQueryRecord", err); } } }
/// <summary> /// This method begins the process of looking up the IP address(es) associated with the current hostname. /// </summary> private void IPLookup() { mAddresses = new ArrayList(); ipLookupReplyCb = new mDNSImports.DNSServiceQueryReply(IPLookupReply); DNSServiceErrorType err; err = mDNSImports.DNSServiceQueryRecord(out ipLookupQueryHandle, 0, 0, HostName, DNSServiceType.A, DNSServiceClass.IN, ipLookupReplyCb, IntPtr.Zero); if (err == DNSServiceErrorType.NoError) { SetupWatchSocket(ipLookupQueryHandle); } else { Stop(); if (DidNotResolveService != null) { DNSServiceException exception = new DNSServiceException("DNSServiceQueryRecord", err); DidNotResolveService(this, exception); } } }