tags:

views:

51

answers:

3

I am having trouble connecting my online application to others across another network. I am able to give them the hostAddress to connect when we are on the same network but when we are doing it across the internet the generated host address doesn't allow a connection, nor does using the ip address gotten from online sites such as whatismyip.com

My biggest issue isn't debugging this code, because it works over intra-network but The server doesn't see attempts when we try to move to different networks. Also, the test port I am using is 2222.

InetAddress addr = InetAddress.getLocalHost();
String hostname = addr.getHostName();
System.out.println("Hostname: " + hostname);
System.out.println("IP: " + addr.getHostAddress());

I display the host to the server when it is starting

if (isClient) {
System.out.println("Client Starting..");
clientSocket = new Socket(host, port_number); 
} else {
System.out.println("Server Starting..");
echoServer = new ServerSocket(port_number);
clientSocket = echoServer.accept();
System.out.println("Warning, Incoming Game..");
}
+6  A: 

If it works on your local lan but not across the internet then one or both peers are probably on a NAT'ed connection, meaning that the public IP address you see on the internet is not the same as the IP address of the machine you are trying to talk to. You would probably need to set up some kind of port forwarding to allow your app to connect.

Robert S. Barnes
Now that you mention it, I think that my Universitiy Network uses that to mask ip addresses. I will do some independent confirmation in the next few hours. I wonder how to get around this.
maleki
Are both machine's on the Uni network or only one? You only need to setup port forwarding on one of the machine's for things to work. Another solution is to use a third machine which is on the open internet as a proxy.
Robert S. Barnes
When testing only one was. I am going to test with having the host machine not be on the university network.
maleki
If the server has a direct connection to the internet, i.e. it's public IP is it's only IP, then it shouldn't matter if the client is NAT'ed. However, it won't work the other way around.
Robert S. Barnes
A: 

Some additional information might be helpful. Can you ping the machine from where you are? Are you attempting to go through a firewall? You say they work over localhost or local network - those are a bit different. Do you mean a network using local space (i.e. 10...* or 192.168.. or the like)? You say you are using a test ip of 2222 - that is not an ip address. Is that the domain of the address? Or is that the port number?

aperkins
A: 

The issue is probably firewall configuration.

Assuming you're testing this at home (it would usually be more complex from a university or company).

Usually you'll need to configure your router to let port 2222 open (you can also open port 5555 and tell your router to redirect to the host you want on your lan (there might be many), and port 2222).

To sum up: other user ----> internet ----> [your modem] internet_IP -> [your router] lan_IP -> your computer lan_IP2

internet_IP is given by your ISP; find it here: http://www.whatismyip.com/ lan_IP: you defined in your router configuration. Typically: 192.168.0.1 lan_IP2: usually given to your PC by the router (DHCP). Find it by typing ipconfig (Windows) or ifconfig (Linux).

You need to tell your router to open port 2222, and route it to lan_IP2 on port 2222. Configuring the router is usually done by connecting on its http interface: http://192.168.0.1

Nicolas
Be careful though, if you leave a port open on the internet... even what seems like a dummy server can sometimes be exploited by hackers.
Nicolas