Search code examples
c#portforwarding

Port forwarding (P2P connection)


Im experiencing a strange situation which i was supposed to handle.

The situation is: 2 routers (with static IPs by ISP) and 2 host computers behind each router. Let's say IP addresses are R1_IPAddr(router 1), R1_IPAddr_LocalH1(host 1 behind router 1) are 1st group and R2_IPAddr(router 2), R2_IPAddr_LocalH2(host 2 behind router 2) are belong to 2nd group.

So, my aim is: To connect R1_IPAddr_LocalH1 with R2_IPAddr_LocalH2. Here what I did: My server code (C#) on R2_IPAddr_LocalH2 and R2_IPAddr router forwards port 5000 to R2_IPAddr_LocalH2 (configured but may require other settings). Server code binds R2_IPAddr_LocalH2 on 5000 port number and waits connection where R1_IPAddr_LocalH1 machine tries to connect to R2_IPAddr router on port 5000.

NOTE: router hasn't any firewall options, means the cheapest one :) and tested my code on local LAN, working fine!

If somebody has any ideas to share pls? Thanks in advance.


Solution

  • Although i have not made this capability yet, I found a good write up on the capabilities Microsoft made, partially explaining the NATUPnP 1.0 Type Library, which is used for configuring and managing port forwarding.

    http://pietschsoft.com/post/2009/02/05/NET-Framework-Communicate-through-NAT-Router-via-UPnP.aspx