I have a Nokia 9500 and want to find out what my IP address is. I wrote this piece of code on and it runs on the emulator (and gives me the correct IP),but only gives me 127.0.0.1 on the phone. I suspect that since the PC is "always on", that the server socket has available to it the IP address before you do an 'serverSocket.acceptAndOpen()'. Is this true?
By the way, I don't really want to do an serverSocket.acceptAndOpen(), because I have no intention of ever connecting to that port, I just want to find out what my IP is.
Cam
public static String getIP() {
String returnValue = "";
ServerSocketConnection socket = null;
try {
socket = (ServerSocketConnection) Connector.open("socket://:",Connector.READ_WRITE,false);
if (socket == null) {
System.out.println("Socket is Null");
System.exit( -1);
}
System.out.println("3");
returnValue = socket.getLocalAddress();
System.out.println("Return Value: " + returnValue);
socket.close();
} catch (IOException ex) {
System.out.println("Exception raised by Network.getIP()");
ex.printStackTrace();
} finally {
try {
if (socket != null) {
socket.close();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
return returnValue;
}
}


Reply With Quote

