I need to establish a tcp connection from my house computer to my office computer.
on the office there is a router where several computers are connected to. that router has internet therefore all the computers connected to that router have internet as well. on my house I have a computer with internet access. I need my office computer to act as the server and my home computer to connect to it. Before, I used to be able to connect by port forwarding traffic on the server as:
NATUPNPLib.UPnPNATClass upnpnat;
NATUPNPLib.IStaticPortMappingCollection mappings;
public ServerExample()
{
InitializeComponent();
upnpnat = new NATUPNPLib.UPnPNATClass();
mappings = upnpnat.StaticPortMappingCollection;
// server local IP address
mappings.Add(1300, "TCP", 1300, "192.168.150.146", true, "plsease work");
// this code tels the router to forward all tcp traffic comming from port
// 1300 to the server computer (it's lan ip address happens to be 192.168.150.146)
//...
and I was able to connect from my house. (I know that the simple way will be to open the ports on the office router and forward them to my computer the problem is that I do not have access to the office router)
now they replaced the router on my office with a newer one and I am not able to use my code.Now, with the new router, when I execute the privious code I get:
note that mappings returns null; therefore, I am not able to add a mapping.
I am sure there should be a way to establish a connection because some people in the office use limewire for example or bit torrent. I think my problem has to do with permissions maybe? How can I resolve this?
Edit
So from researching I found that what I am trying to do is "UDP punch hole into firewall". I actually want to do it over a tcp connection. I don't know what is will be the difference between tcp and upd puch holing.... I mean the purpose of that is for a client to be able to find a pear without having to do configurations on the router.
.
.
.
.
.
.
UPDATE
OK so I believe I have tried doing what you guys posted on this question with c#: ok let me show you what I did:
note you may need to refer to this diagram in order to understand what I will be explain:
As you know I want to establish a tcp connection between computer A and computer B. The way I manage to do this is by doing what is called tcp punch holing.
Step 1:
The first thing that I do is to start listening for new connections on the server S.
TcpListener server = new TcpListener(System.Net.IPAddress.Parse(“192.168.11.109”), 55550);
Server.Start();
var client = server.AcceptSocket(); \ wait here until someone connects
Step 2:
Now connect to the server with computer A as:
TcpClient tcpClient = new TcpClient("192.168.11.109", 55550);
Step 3:
After executing step 2 code on computer A the server S debug should look like:
Step 4:
Now our goal is to connect from computer B to computer A. Server S has the information that B needs in order to establish the connection. In reality I will have to establish a connection between computer B and server S so that server S can give B the appropriate parameters in order for B to connect to A.
Step 5:
since I am debuging I am able to see the parameters so I will make computer A a server now by listening on port 3313. I want computer A to be listening now on that port (3313) because all the packages sent to router X with port 3313 should be sent to computer A.
\ COMPUTER A
TcpListener server = new TcpListener(System.Net.IPAddress.Parse("192.168.0.120"), 3313);
server.Start();
var newClient = server.AcceptSocket(); \ wait here until a client gets connected
Step 6:
So computer A should now be listening for new connections on port 3313. again port 3313 is important because router x should forward all packages received from that port to computer A.
Computer A is waiting for new connections.
Step 7:
So now quickly! We want to establish that connection from computer B. In reality server S will pass the parameters but since I am just trying to make this work I will write the program really quick on computer B.
TcpClient tcpClient = new TcpClient(“192.168.11.108”, 3313);
\192.168.11.108 is the address of router X
Finally:
For some reason, computer B is not able to connect to computer A.
The reason why it is not able to connect is because router X did not forwarded the packages to computer A. (I know this because I have enabled port forwarding on port 54540 on router X and when I use that port it works) I mean I don’t understand why router X did not forward traffic coming from port 3313 to computer A. Computer A already established a connection to server S and all the things that server S sent to router X through port 3313 got sent to computer A. why is it that if I send packages to router X through port 3313 they don’t get received by computer A!?
PS:
Note that everything that I showed here, I actually have the three routers X, Y and Z and also I have server S, computer A and computer B:
See Question&Answers more detail:
os