when client send msg by UDP, How to know the IP of client?



  • Now I have a computer as server,there are some device connect to my computer as client. Those device always send message to my computer by UDP , and I make a programme to receive those messages.

    const QString IP_ADDRESS = "192.168.15.114";
    const int PORT = 23333;
    //...
    rece_UDP = new new QUdpSocket(this);
    rece_UDP->bind(QHJostAddress(IP_ADDRESS),PORT); 
    //...
    

    those device send messages to this IP(IP of my computer),and I can receive those message,and ......I need send message back by UDP....
    Now there is a problem, the message from device don't include IP of device, i need know the IP oo device so i can send message back.But how to know the IP of these device?
    My boss say there's a methon that can get client's IP when the client send message by UDP...
    If my boss is right ( As you know , boss is awlays right....),how to get client's IP when client send the message by UDP?



  • In Qt you have a function http://doc.qt.io/qt-5/qudpsocket.html#readDatagram and you can read ip of sender from this function.
    Here you have also tutorial how to use it: http://www.bogotobogo.com/Qt/Qt5_QUdpSocket.php.



  • @qazaq408
    You look at the server's QUdpSocket's data receiving methods for this, as they will include the sender's IP address, e.g. http://doc.qt.io/qt-5/qudpsocket.html#readDatagram


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.