简体   繁体   中英

IP address will not connect to same IP address

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!");    
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM