If you get 0.0.0.0, this is probably because your listening socket accepts connections on all machine interfaces. As a rule, there will be at least two of them - one for communication with the outside world and the localhost / loopback interface. Therefore, it makes no sense to ask for one address.
Once you accept an incoming connection, you can give it the address of a specific interface that processes it.
A quick way to find a “good” IP address is to make an outgoing connection to a known site and request the address of its local end after it is connected. This is somewhat more portable than enumerating network interfaces (if you care about such things), but, of course, it requires that you have something that you can connect to the one you trust in order to be lively and achievable.
source share