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. I want to use udp that specified IP to send data
Forum Updated to NodeBB v4.3 + New Features

I want to use udp that specified IP to send data

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 3.5k 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.
  • S Offline
    S Offline
    spite
    wrote on last edited by
    #1

    UDP server needs bind the ip and port to receive data,how to specified the ip of the udp client?
    now my pc has multiple IPs,I want to use the speified the ip to send data by udp.what should I do?

    J.HilkJ 1 Reply Last reply
    0
    • S spite

      UDP server needs bind the ip and port to receive data,how to specified the ip of the udp client?
      now my pc has multiple IPs,I want to use the speified the ip to send data by udp.what should I do?

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      Hi @spite ,

      I'm not quite sure what you're after.

      QUDPSocket has 2 functions to bind itself, derived from QAbstractSocket

      bool QAbstractSocket::bind(const QHostAddress &address, quint16 port = 0, BindMode mode = DefaultForPlatform)
      

      and

      bool QAbstractSocket::bind(quint16 port = 0, BindMode mode = DefaultForPlatform)
      

      I, for example, use this line

      m_udpSocket->bind(8001, QUdpSocket::ShareAddress);
      

      to lisen to all signals/data received at socket 8001 in my local Network.

      and use QUdpSocket::readyRead to process/interpret all received data


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      S 1 Reply Last reply
      5
      • Pablo J. RoginaP Offline
        Pablo J. RoginaP Offline
        Pablo J. Rogina
        wrote on last edited by
        #3

        @spite said in I want to use udp that specified IP to send data:

        how to specified the ip of the udp client?

        you don't specify the IP address of the UDP client, you "bind" your UDP socket to an IP address and port in your machine, and it starts listening to client connections.
        You may want to take a look at QUdpSocket documentation for more information

        Upvote the answer(s) that helped you solve the issue
        Use "Topic Tools" button to mark your post as Solved
        Add screenshots via postimage.org
        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        3
        • J.HilkJ J.Hilk

          Hi @spite ,

          I'm not quite sure what you're after.

          QUDPSocket has 2 functions to bind itself, derived from QAbstractSocket

          bool QAbstractSocket::bind(const QHostAddress &address, quint16 port = 0, BindMode mode = DefaultForPlatform)
          

          and

          bool QAbstractSocket::bind(quint16 port = 0, BindMode mode = DefaultForPlatform)
          

          I, for example, use this line

          m_udpSocket->bind(8001, QUdpSocket::ShareAddress);
          

          to lisen to all signals/data received at socket 8001 in my local Network.

          and use QUdpSocket::readyRead to process/interpret all received data

          S Offline
          S Offline
          spite
          wrote on last edited by
          #4

          @J.Hilk said in I want to use udp that specified IP to send data:

          functions

          My computer has a lot of IP,It has 192.168.168.100 、192.168.9.100、192.168.163.100 and so on. I want use the 192.168.163.100 to send a udp packet.

          J.HilkJ 1 Reply Last reply
          0
          • S spite

            @J.Hilk said in I want to use udp that specified IP to send data:

            functions

            My computer has a lot of IP,It has 192.168.168.100 、192.168.9.100、192.168.163.100 and so on. I want use the 192.168.163.100 to send a udp packet.

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @spite

            well sure, than use:

            bind(QHostAddress("192.168.163.100"),myPort,QAbstractSocket::DefaultForPlatform);
            

            or very similar to this.


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            6

            • Login

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