2013年8月21日星期三

Android Mobile IP is moving to know how to change

There is no system comes with state of the class, or you'll see yourself on a regular basis?
------ Solution ---------------------------------------- ----
in and server interaction, often will use the client ip address. Of course, the request on the server side can get over ip, in the mobile terminal, how it gets its own ip? Refer to the following function:

view plain

public static String GetHostIp {

try {

for (Enumeration en = NetworkInterface

. getNetworkInterfaces; en.hasMoreElements ;) {

NetworkInterface intf = en.nextElement;

for (Enumeration ipAddr = intf.getInetAddresses; ipAddr

. hasMoreElements ;) {

InetAddress inetAddress = ipAddr.nextElement;

if (! inetAddress.isLoopbackAddress) {

return inetAddress.getHostAddress;

}

}

}

} catch (SocketException ex) {

} catch (Exception e) {

}

return null;

}

In fact, under the above methods related classes through java.net get the ip. Mainly used in class has: java.net.NetworkInterface and java.net.InetAddress
------ reference ---------------------- -----------------

java.net.BindException: Address already in use: Cannot bind
at java.net.DualStackPlainDatagramSocketImpl.socketBind (Native Method)
at java.net.DualStackPlainDatagramSocketImpl.bind0 (DualStackPlainDatagramSocketImpl.java: 65)
at java.net.AbstractPlainDatagramSocketImpl.bind (AbstractPlainDatagramSocketImpl.java: 95)
at java.net.DatagramSocket.bind (DatagramSocket.java: 376)
at java.net.DatagramSocket. (DatagramSocket.java: 231)
at java.net.DatagramSocket. (DatagramSocket.java: 284)
at java.net.DatagramSocket. (DatagramSocket.java: 256)
at com.example.Server.Server.main (Server.java: 16)
Exception in thread "main" java.lang.NullPointerException
at com.example.Server.Server.main (Server.java: 23)
Paul so much wrong strange
------ reference ------------------------------- --------
back too much. than a dozen, but the format is
fe80: 0:0:0:0:5 efe: c0a8: 267% 22
I can understand there
192.168.1.105
not the external network IP

没有评论:

发表评论