We want to establish TCP/IP connection between two android devices. For now we thought that it would be simpler if we make the connection device to device. So there is no se
Well to make a TCP socket one device must be listening and the other connecting. However in a real world scenario what you describe is sort of hard. Like if you are going to communicate over a cell network between two phones, I wouldn't be surprised if the network did not allow inbound connections to a phone like that and just sandboxed each phone's IP. So while two phones might be on the same subnet IP range, they might not be on the same physical network which just makes the whole routing problem almost impossible.
If you are in control of the network and are using Wifi and natting the IPs yourself with both devices within your network, you should be able to do this just like any other client server TCP socket.