if (FriendFunctions.serverIsLookingForClient(name)) {
try {
String ip = LoginFunctions.getOtherIP(name);
System.out.println("other: " + ip);
if (ip.equals(BasicFunctions.getIpv4()))
ip = "127.0.0.1";
Main.myClient = Network.connectToServer(ip, 8972);
Main.myClient.start();
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
this.switchStates(new OnlineClientCharacterSelectState(new RequestFriend()));
} else {
try {
Main.myServer = Network.createServer(8972);
Main.myServer.start();
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
FriendFunctions.lookForClient(name);
this.switchStates(new OnlineServerCharacterSelectState(new RequestFriend()));
}
The above is my code for a server and client to connect with each other.
When running two copies of the app from Eclipse, it works perfectly- regardless of which copy is the server and which is the client.
I exported my app to a jar, and ran the app both using the jar and using Eclipse. Again, it works perfectly, no matter which is the server and which is the client.
Then I transferred the jar over to another machine (on the same network), and tested using that and the version on the original machine using Eclipse.
Here’s where things get weird. If the jar version on the other machine is the server, the Eclipse version connects as a client perfectly. If the Eclipse version is the server, however, attempting to connect using the jar version causes a Connection Refused error.
The FriendFunctions, LoginFunctions, and BasicFunctions stuff are functions for my FTP site and are all working properly- that is to say, the IP gotten by the soon-to-be client is the one used by the server to log into the site. There is no chance of this being incorrect.
So without the IP address being incorrect, how could this happen? How would being on separate machines affect the client side for one but not the other?
(Through testing, I have determined that the server is up and running by the time the client tries to connect, so that isn’t the issue either)