TCP Sockets LocalAddress and RemoteAddress 0's

Monkey Forums/Monkey Programming/TCP Sockets LocalAddress and RemoteAddress 0's

benmc(Posted 2013) [#1]
When I use LocalAddress or RemoteAddress on a Socket, all I'm getting is 0.0.0.0 every time. Does anyone know how to get the IP address of the device that's using Sockets?


Sub_Zero(Posted 2013) [#2]
For android, check out http://www.monkeycoder.co.nz/Community/posts.php?topic=3275


benmc(Posted 2013) [#3]
Fortunately for me, Android is a pretty familiar environment. With the help of Stackoverflow, I was able to put together a function and add it to the brl socket.java that does something like:

String GetLocalIPAddress() {
	
		String hostAddress = "127.0.0.1";
		
	    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()) {
	              hostAddress = inetAddress.getHostAddress().toString();
	              }
	            }
	          }
	    } catch (SocketException ex) {
	        // Log.e("ServerActivity", ex.toString());
	    }
	    
	    return hostAddress;
	
	}


Now, the GLFW, iOS, etc. That's tough for me, not sure what I'm doing, but may have found a cpp solution that I'm trying to hack together at the moment.