Reputation: 1886
I have this problem with the application I'm coding right now.
I'm coding a server and client application using Sockets .NET. The server runs on a machine with a static IP of 192.168.1.6. The client has no problem connecting to that IP address over LAN. But when I set up the client to connect to my WAN IP, the connection could not be made.
Of course I immediately thought of port forwarding, so I configured my router to accept incoming connections on the port I use for the application and the machines static IP. I even checked if the port was correctly forwarded using the PFPortChecker tool by portforward.com (and it was), but I can't seem to get it to work.
Is there something I'm overlooking here? I really hope somebody can help me out, because I'm literally pulling out my last hairs now...
EDIT:
Ok, I've narrowed the problem down to a .NET Socket issue.
Basically when I try to connect with the following code (C#):
Socket _client;
_client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_client.Connect("XX.XXX.XXX.X", XXXX);
The connection could only be made within a LAN environment. however, when I have an instance of the server running on my machine, and I try to ping the WAN IP and port using the PFPortChecker tool, I actually get a response in my server, and it starts to handle the incoming connection as a new client.
Any idea how I can fix my code so the connection can be made over WAN?
EDIT 2:
Ok, so I figured out what the problem was. I am not able to connect from my own WAN IP to my own WAN IP. On another network I have no problem connecting to my server.
Thanks for your trouble anyway.
Upvotes: 0
Views: 357
Reputation: 2927
192.168.1.6 is a LAN subnet ... your external IP is different. If port forwarding is fine than that's probably the problem. Google "what's my ip" and it should tell you your external ip address
Upvotes: 0
Reputation: 137448
I would first recommend running Wireshark on the server, to see if he is seeing the incoming connections. That will confirm whether or not the router is forwarding traffic on that port to the machine or not.
Upvotes: 3