I have had no trouble getting the sockets working with localips, but once I made the code change to use public ips, I've consistently gotten java.net.ConnectException.
I am using the port 8084, which as far as I know, is not used elsewhere In the command prompt, netstat -a | grep 8084 shows: File STDIN: TCP user-9114eb19a8:8084 user-9114eb19a8:0 LISTENING
I have gone into my router and ensured that it is open I get my public ip using a request to http://www.whatismyip.org
Server:
serverSocket = new ServerSocket (8084);
Client:
socket = new Socket (hostaddr, 8084); //hostaddr is a string containing my public-IP
//it works when the program is run on a localnetwork and I am using my local-ips