I start a server socket , and hope it listen on the loopback address(127.0.0.1). The code is as following: ......
Inet4Address address = (Inet4Address) Inet4Address.getByName("localhost");
TServerSocket server = new TServerSocket(new InetSocketAddress(address ,1234));
.........
public class TServerSocket{
......
public TServerSocket(InetSocketAddress bindAddr, int clientTimeout) throws TTransportException {
clientTimeout_ = clientTimeout;
try {
serverSocket_ = new ServerSocket();
serverSocket_.setReuseAddress(true);
serverSocket_.bind(bindAddr);
} catch (IOException ioe) {
serverSocket_ = null;
throw new TTransportException("Could not create ServerSocket on address " + bindAddr.toString() + ".");
}
}
......
}
But I found that this socket starts to listen on an IPv6 address ":ffff:127.0.0.1" with the command "netstat", and it caused that a client running in another process(in Python) can't connect to this server through "127.0.0.1".
Why android automatically mapped an IPV4 address to an IPv6 address ?