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

How can I associate the udp or tcp socket with the interface?



  • Folks,
    How can I connect the udp and tcp socket to an interface. For example, there is a wifi and an ethernet controller on the computer. Can I send and receive data to the network by selecting the socket I created, wifi or ethernet adapter?

    I want to show the controllers on a combobox. Whatever choice does the user make, create the socket on it and send and receive data?

    Thank you very much for your help.

    Happy codings,

    Thank you


  • Lifetime Qt Champion

    Hi,

    Do you mean bind the socket ?

    Isn't the first parameter what you are looking for ?



  • if you are talking about the physical interface (by name), that is platform dependent. The normal and accepted way of doing socket programming is by address and the system routing tables choose the correct interface based on that information.



  • @SGaist said in How can I associate the udp or tcp socket with the interface?:

    Hi,

    Do you mean bind the socket ?

    Isn't the first parameter what you are looking for ?

    QList<QNetworkInterface> list = QNetworkInterface::allInterfaces();
           foreach (QNetworkInterface iface, list)
           {
               ui->comboBox->addItem(iface.humanReadableName());
            }
    

    I added to the combobox element I listed in the code I shared above and created the adapter constructor that I selected in socket-> QUdpSocket (); bind to the object. I looked at what you said but I could not understand unfortunately: /


Log in to reply