lontivero / Open.NAT

Lightweight and easy-to-use class library to allow port forwarding in NAT devices with UPNP and/or PMP
MIT License
421 stars 99 forks source link

DiscoverDeviceAsync exception #29

Closed Naor-D closed 9 years ago

Naor-D commented 9 years ago

Forgive me if this is a total beginner's question, but I wrote the following piece of code:

    public async void ForwardPorts()
    {
        try
        {
            NatDiscoverer natDiscover = new NatDiscoverer();
            NatDevice natDevice = await natDiscover.DiscoverDeviceAsync();
            await natDevice.CreatePortMapAsync(new Mapping(Protocol.Tcp, IPAddress.Loopback, 53100, 53100, 0, "New Port Forwarded"));
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

The goal of this function is simply to forward port 53100.

I'm calling ForwardPorts() from my main function, but I get an exception: "An existing connection was forcibly closed by the remote host", do you have any idea how I can fix this or what am I doing wrong? I would really appreciate the help, thanks in advance.

lontivero commented 9 years ago

@TheMan654 please download and run the Open.NAT.ConsoleTest project. After that, you will find the network.log log file (in the Output Directory) with absolutly all the information needed for diagnostic. Please, do that and review the log file, or send it to me.

Naor-D commented 9 years ago

Thanks for the help, and for the fast response! I managed to fix my problem, it was that I wrote: NatDevice natDevice = await natDiscover.DiscoverDeviceAsync();

Instead of: NatDevice natDevice = await natDiscover.DiscoverDeviceAsync(PortMapper.Upnp, cts);

Also thank you for the library, it really helped me a lot in my project.