views:

101

answers:

3
+1  Q: 

IP address problem

I built a TicTacToe game application (I'm using TCP protocol) that consist of server and client (that run two times to represent the 2 opponents). I have a problem and I can't find the solution for it, that is why I'm asking this question. the problem is : when the client try to connect the server on my machine, it never connect because of the IP address(obtained from the support tab from the local area connection in my windows) of my machine isn't correct. I tried to obtain my IP address from websites that told you your IP but I doesn't work. I have a problem to determine my IP address that any machine can connect to me from anywhere. p.s. I'm using router to connect the internet. thanks.

+3  A: 
            string procCall = "http://project-intercept.com/ip.php";
            WebClient wc = new WebClient();
            UTF8Encoding utf8 = new UTF8Encoding();
            string requestHtml = "";
            requestHtml = utf8.GetString(wc.DownloadData(procCall));                
            return requestHtml;

You can either use project-intercept.com/ip.php (witch is my anti-cheats project site) or you can use whatsmyip.org/ip.php (i think is the url). Basically any URL thats echo's just the ip. If you want to host the php yourself create a php file and add this

echo $_SERVER['HTTP_CLIENT_IP'];

or

echo $_SERVER['REMOTE_ADDR'];
Dremation
Not Working ,too.
mavric
I know 100% that that code snippet works. Make sure your firewall isn't blocking your application, same for the router. If you need a full example on how to use it let me know. Remember to use System.Net and System.Web
Dremation
what is "Settings.Log.Write("GetMyIP(): My IP is: " + requestHtml);" from where you got "Setting" ?
mavric
Sorry, Settings is a custom Namespace that I was using in that particular project. Please discard that.
Dremation
+3  A: 

First I'd check to make sure any local settings and whatnot are correct by running the server and clients on the same machine, and using localhost or 127.0.0.1 directly as the ip address. If this doesn't work, you have a problem in either your code or your local firewall, which you'll have to fix before you look into router stuff.

Local firewall is easy enough to check, just disable all your firewalls completely to see if you can connect to localhost. If you cannot connect with firewalls completely disabled, it's your code that you need to fix first.

If that does work, then play around with allowing your (server) application through the firewall to accept traffic. Client application opening a connection won't (shouldn't) have any firewall issues on its own, as that's solicited traffic that firewalls usually don't interfere with.

If/when you can connect to localhost, you can try connecting through the internet, through your router. Most likely, your problem is your router not forwarding the port that you're opening to your computer. I've only ever implemented port forwarding manually myself, and you should probably look into what this is and why it's needed yourself before messing with things. Basically, you want the client to connect to your public ip (what you find from whatsmyip.org or wherever), and your router to forward to your LAN ip (what you find in the support tab of local area network config). Step by step instructions for this are router-specific, but are usually straight-forward (there's usually a 'firewall' and/or 'advanced' tab or something in the router management page).

You could eventually try to implement upnp, which doesn't seem too complicated from a quick google search, but it's probably too complex for the stage of learning you're probably in.

Tanzelax