Reputation: 880
EDIT: This question was written by someone else in my project group. It's not very well worded, or informative, so if you've stumbled here by some accident let me know if you need any clarification etc.
The server sends the IP address through a message to the client. Our client then reads the message and displays the IP address by reading it. I have it where it gathers the right numbers, but does not connect when back to the sent IP address. Any idea why it won't connect even with the same address? The code is given below:
byte IPAddr[] = Arrays.copyOfRange(message, 3, 7); //and that is equal to "0.0.0.1"
try {
InetAddress IP = InetAddress.getByAddress(IPAddr);
Socket clientSocket = new Socket(IP, returnPort);
System.out.println("Connected!");
}
Upvotes: 2
Views: 155
Reputation: 500873
The server has multiple IP addresses. For this to work, the address it gives to the client must be its external IP address. One example that won't work is the loopback address, 127.0.0.1, even though it's a correct IP from the server's point of view.
Upvotes: 2