Exemplo n.º 1
0
        static void Main(string[] args)
        {
            NATUPNPLib.UPnPNAT _upnpTranslator = new NATUPNPLib.UPnPNAT();
            _upnpTranslator.StaticPortMappingCollection.Remove(45000, "UDP");

            //using (MulticastServer server = new MulticastServer(45000, "UDP", 45000, "My server"))
            //{
            //    while (true)
            //    {
            //        server.SendMessage("some message");
            //        System.Threading.Thread.Sleep(3000);
            //    }
            //}
        }
Exemplo n.º 2
0
        private void UPnPOpenPort()
        {
            Console.WriteLine("[UPnP]: Sending port forwarding data!");
            AppSettings settings = AppSettings.GetInstance();
            NATUPNPLib.IUPnPNAT upnpnat = new NATUPNPLib.UPnPNAT();
            NATUPNPLib.IStaticPortMappingCollection mappings = upnpnat.StaticPortMappingCollection;
            bool mapped = false;
            try
            {
                foreach (NATUPNPLib.IStaticPortMapping mapping in mappings)
                {
                    //Console.WriteLine("[UPnP]: Mapping -> ip: "+mapping.InternalClient.ToString()+" port: " + mapping.InternalPort.ToString());
                    if (this.LocalIPAddress().ToString() == mapping.InternalClient.ToString() && mapping.InternalPort.ToString() == settings.NCPort.ToString())
                        mapped = true;
                }
            }
            catch (Exception e)
            {
            }

            if (!mapped)
            {
                try
                {
                    mappings.Remove(settings.NCPort, "TCP");
                }
                catch (Exception e)
                { }

                try
                {
                    mappings.Add(settings.NCPort, "TCP", settings.NCPort, this.LocalIPAddress(), true, "OpenGraal NPCServer");
                }
                catch (Exception e)
                { }
            }
        }