I have two android devices and they are connected to a same WiFi network. One device acts as the server and the other acts as the client. I don't know the ip of the server but I know the port number. How can I find the server and connect to it?
One option is to use UDP broadcasting. Your server is waiting for requests on a specific port and network interface. Then your client send a dummy request against the broadcast address (like for instance 192.168.1.255) and once the server replies you can get the server's ip address.
Once you're done, the client can shutdown the udp socket connection and start tcp communication as you need.
A good start might be this: http://michieldemey.be/blog/network-discovery-using-udp-broadcast/
Hope this helps