Here'e the problem.
I have two android phones, both connected to the same wi-fi network. One phone is listening with a ServerSocket and the other attempts to connect with this socket.
However, this is not happening. (i.e) The connection does not get established. However, when I create a listening ServerSocket on my PC (also on the same network) and set my phones to connect to the PC, the connection is established.
In other words, I am able to create the connection between a phone and PC but not between phone and phone. Does anyone have any idea of what might possibly be causing this problem?
Thank you!
Below is the code I have used for getting the IPv4 address.
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int ipAddress = wifiInfo.getIpAddress();
int[] address = new int[4];
String ip = "";
for (int i = 0; i < 4; i++) {
address[i] = ipAddress % 256;
ipAddress /= 256;
if (i != 3)
ip += (String.valueOf(address[i]) + ".");
else
ip += String.valueOf(address[i]);
}
return ip;
Edit:
I tried logging the exact location and cause and it gave the following error:
java.net.SocketException: No route to host at
org.apache.harmony.luni.platform.OSNetworkSystem.connect(Native Method) at
dalvik.system.BlockGuard$WrappedNetworkSystem.connect(BlockGuard.java:357) at
org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:207) at
org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:186) at
java.net.Socket.startupSocket(Socket.java:735) at
java.net.Socket.<init>(Socket.java:263) at
com.test.word.WifiActivity$12.run(WifiActivity.java:460) at
java.lang.Thread.run(Thread.java:1027)