0

I want to code a UDP server and I want to use my IP address as the address of the server without putting the code the address in raw.

myIP="192.168.1.38";

is there any way to get the IP of the host machine ?

i know that QHostAddress::LocalHost is equivalent to 127.0.0.1. is there any method that works the same to get my IP ?

  • Does this answer your question? [Get local IP address in Qt](https://stackoverflow.com/questions/13835989/get-local-ip-address-in-qt) – Richard Critten Mar 02 '23 at 18:16
  • Also [How to get your public ip address using Qt c++](https://stackoverflow.com/questions/66008089/how-to-get-your-public-ip-address-using-qt-c) – Richard Critten Mar 02 '23 at 18:17
  • 1
    Note that the host machine may have multiple IPs assigned to it. Typically, it is best to just bind to `"0.0.0.0"` to listen on all local IPs. You should bind to a specific IP only if you want to listen only to a specific network (if the machine is connected to multiple networks). – Remy Lebeau Mar 02 '23 at 19:53

0 Answers0