Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd a NAT UPnP mapping on a complex network using C#
    primarykey
    data
    text
    <p>I am creating an application that listens for connections (server) from a different application (client) via a tcp connection. So if both application where to be on the same network it will be easy to establish the connection. so I am trying to add a method to the server so that users do not have to open ports on their routers in order to make the app work when using it over the internet. so let me show you a few different scenarios:</p> <p>1)---------------------------------------------------SCENARIO_1-------------------------------------------------------------</p> <p>the server is a computer in a house. That computer is connected to a router and that router is connected to the internet. The client is a computer on a office that has access to the internet as well.</p> <p>for this scenario to work, before I used to open the ports on the house router and forward them to the server computer. on the client I just had to supply the correct IP address and same port in order to establish the connection. </p> <p>now I avoided opening the ports on the house router with a really cool technique:</p> <p>first I add this reference:</p> <p><img src="https://i.stack.imgur.com/Mkx9g.png" alt="enter image description here"></p> <p>then I tell the router which ports I want to be forwarded to my computer (the server):</p> <pre><code> NATUPNPLib.UPnPNATClass upnpnat; NATUPNPLib.IStaticPortMappingCollection mappings; public ServerExample() { InitializeComponent(); // server local IP address mappings.Add(1300, "TCP", 1300, "192.168.0.120", true, "my server"); //.... etc .. </code></pre> <h2>when doing this I am able to connect from my office computer by providing port 1300, the WAN ip address of the server computer which is a different one. (that address can be found at: whatismyipaddress.com) THE COOL THING IS THAT I DO NOT HAVE TO DO ANY CONFIGURATION ON THE ROUTER!!!</h2> <p>2)-----------------------------------------------SCENARIO_2----------------------------------------------</p> <p>know here comes my problem. The server happens to be on a office. that server is connected to router A, router A is connected to router B and router B is connected to the internet. In other this example is like the last example on the server with an extra router in between. and the client is somewhere else. we do not care how the network setup is on the client computer as long as it has internet access. </p> <p>the way I used to solve this was by forwarding the packages from router x to the server computer and also port forwarding the traffic from port x of router B to the ip address of router A. when setting up that configuration I was able to establish a connection with the client when providing the WAN ip address of the server. (the ip address that is shown at: whatismyipaddress.com when retrieved from the network of the office).</p> <p>so it will be nice if I can avoid doing all this configuration on the routers and do something similar to:</p> <pre><code> public delegate void SomeDelegate(string parameters); NATUPNPLib.UPnPNATClass upnpnat; NATUPNPLib.IStaticPortMappingCollection mappings; public ServerExample() { InitializeComponent(); // server local IP address mappings.Add(1300, "TCP", 1300, "192.168.150.141", true, "my server"); mappings.Add(1300, "TCP", 1300, "another ip", true, "router's ip"); </code></pre> <p>so I have been playing around with that and I have not been able to make it work. also it will be nice if I could find out if the server connection is like scenario 1 with c# or scenario 2 or maybe a different scenario so that the users setting up the server do not have to specify all that info. for example I am sure that limewire does something similar. </p> <hr> <p>Edit:</p> <p>here is scenario 1 illustrated:</p> <p><img src="https://i.stack.imgur.com/Oialx.png" alt="enter image description here"></p> <p>and here is scenario 2 illustrated</p> <p><img src="https://i.stack.imgur.com/6UEmw.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload