제가 2개의 안드로이드 폰으로 1:1 소켓 통신을 하려고 합니다. 

1개가 서버로 구동되면 나머지 1개가 클라이언트로 접속하는 형식입니다. 

서버가 실행되면 서버가 소켓통신을 열어서 클라이언트를 기다리는데 클라이언트는 서버의 ip address를 입력하여 접속합니다. 


폰한개는 2.3.6이고 나머지 하나는 4.03입니다. 

ip address 를 얻어오는데서 한가지 문제가 있습니다. 


private String getLocalIpAddress() {

try {

for (Enumeration<NetworkInterface> en = NetworkInterface

.getNetworkInterfaces(); en.hasMoreElements();) {

NetworkInterface intf = en.nextElement();

for (Enumeration<InetAddress> enumIpAddr = intf

.getInetAddresses(); enumIpAddr

.hasMoreElements();) {

InetAddress inetAddress = enumIpAddr.nextElement();

if (!inetAddress.isLoopbackAddress()) {

Log.v("socket", "get");

return inetAddress.getHostAddress().toString();

}

}

}

} catch (SocketException ex) {

ex.printStackTrace();

}

return null;

}


 안드로이드폰 자신이 자기의 ip address를 얻어오는 부분인데 2.3.6에서는 정확한 주소를 받아오지만 4.03에서는 알수없는 문자를 나열하여 출력합니다. 


 4.03버전에서는 ip 주소를 받아오는 방법이 바뀌었는지 그렇다면 어떻게 받아올수 있는지 궁금합니다. 

 

 * 두개 모두 와이파이로 인터넷을 연결하고 있으며 설정창에서 와이파이주소를 직접보고 입력하면 소켓통신을 하고 있습니다.