// Universal Plug and Play // UPnP is used in this demo to programmatically manipulate // port forwarding entries on the user's router. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace UPNP { class Program { // Check for errors and deal with them static void CheckError() { if(mn.GetErrorFlag() == true) { Console.Clear(); Console.WriteLine("An unexpected error has occurred. This indicates that Universal Plug and Play is disabled or is not functioning properly on your computer or network."); Console.WriteLine(); Console.WriteLine("Details of this error are as follows:"); Console.WriteLine("Full error message: " + mn.GetErrorFull()); Console.WriteLine(); Console.WriteLine("Operation: " + mn.GetErrorOperation()); Console.WriteLine("Command: " + mn.GetErrorCommand()); Console.WriteLine("Code: " + mn.GetErrorCode().ToString()); Console.WriteLine("Line: " + mn.GetErrorLine().ToString()); Console.WriteLine("File: " + mn.GetErrorFile()); Console.WriteLine(); Console.Read(); } } // Update NAT non blocking static void DoUpdate(bool ReloadInfo, string Title) { if(ReloadInfo == true) { // Start update NAT action without blocking Console.WriteLine("Updating NAT..."); long Action = mn.UpdateNAT(false); CheckError(); // Wait for update to finish int iResult; do { iResult = mn.PollUPNP(Action); Thread.Sleep(1); }while(iResult == 2); // Loop until action is completed CheckError(); } // Display information loaded by mnUpdateNAT Console.Clear(); Console.WriteLine("Port map information " + Title); for(uint n = 0;n