Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. when client send msg by UDP, How to know the IP of client?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 3 Posters 628 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • qazaq408Q Offline
    qazaq408Q Offline
    qazaq408
    wrote on last edited by aha_1980
    #1

    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?

    JonBJ 1 Reply Last reply
    0
    • tomasz3dkT Offline
      tomasz3dkT Offline
      tomasz3dk
      wrote on last edited by tomasz3dk
      #2

      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.

      1 Reply Last reply
      4
      • qazaq408Q qazaq408

        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?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @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

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved