Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to connect tcp socket to current wlan ip address on run time??



  • Hello,

    Since, the wlan ip adreess keeps changing based on network connected.
    Is there a way in QT where I can dynamically read current internet connected ip address and connect my tcp socket to same.

    So on server side, I have server->listen(QHostAddress::Any, port) and on client side clientSocket->connectToHost(192.168.xxx, port).
    Is there anyway I can connect client socket getting current ip address and don't have to hard code it.


  • Lifetime Qt Champion

    @Ronak5 said in How to connect tcp socket to current wlan ip address on run time??:

    Is there anyway I can connect client socket getting current ip address and don't have to hard code it.

    That's one of the reasons DNS was invented.

    So set up your (WLAN) router to assign names to your devices [1] and then connectToHost("yourname", port).

    Regards

    [1] most often the computers name is automatically assigned


Log in to reply