The problem is that your PC is most likely sitting behind a router. The router maps multiple private IP addresses to one public IP address. How does it do that? It uses NAT. In very basic terms, when a device D1 (say with private ip 192.168.1.10), sits behind a router and wants to communicate with a public device D2, it sends a request. The request goes to the router. The router adds the public IP address and an arbitrary port (e.g. 12345) to the packet. The router keeps a table with all ports linked with the private devices (e.g. 192.168.1.10 -> 12345, ...). Then it sends the packet to D2 using D2's public IP address. D2 sends a response back to the router public IP. The router forwards the packet to the private device using the port number and the table, in this case the device is D1.
So, you can't directly communicate with a device sitting behind a router from outside the router. However, you can use port forwarding. You can tell the router to always map a specific port to a specific private IP (your PC's IP). Then, you make the other deivce (your Android app) communicate with it using that port.
In summary, if we have two devices, A and B, and A is behind a router. If A wants to initiate a connection with B, then:
if B is behind the same router, then they can use their private IP addresses.
if B is not behind any router, then A can communicate with it using B's public IP address, as demonstrated above.
- If B is behind a different router, then there must be some kind of port forwarding.