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. QudpSocket bind

QudpSocket bind

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.3k Views 2 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.
  • yuvaramY Offline
    yuvaramY Offline
    yuvaram
    wrote on last edited by
    #1

    HI,

    socket = new QUdpSocket;
    socket->bind(QHostAddress::Any,12345);

    In place of QHostAddress::Any ,need to add specific IP addresses (i.e., 192.168.1.18,192.168.1.19, 192.168.1.21) instead of accepting all the IP addresses.
    I want to bind fixed 3 IP addresses only.
    Thank you .

    Yuvaram Aligeti
    Embedded Qt Developer
    : )

    Paul ColbyP 1 Reply Last reply
    0
    • yuvaramY yuvaram

      HI,

      socket = new QUdpSocket;
      socket->bind(QHostAddress::Any,12345);

      In place of QHostAddress::Any ,need to add specific IP addresses (i.e., 192.168.1.18,192.168.1.19, 192.168.1.21) instead of accepting all the IP addresses.
      I want to bind fixed 3 IP addresses only.
      Thank you .

      Paul ColbyP Offline
      Paul ColbyP Offline
      Paul Colby
      wrote on last edited by Paul Colby
      #2

      Hi @yuvaram,

      I want to bind fixed 3 IP addresses only.

      As far as I know, the underlying OS sockets (on Linux, at least) only support one or all interfaces for a single bind. Qt probably doesn't extend on that.

      So I think you would need to have three separate UDP binds, but you can connect them all to the same slot anyway, like:

      MyClass::MyClass() {
          for (const QHostAddress &address, addresses) {
              QUdpSocket * const socket = new QUdpSocket(this);
              connect(socket, SIGNAL(readyRead()), this, SLOT(mySlot()));
              socket->bind(address, 12345);
          }
      }
      
      void MyClass::mySlot() {
          QUdpSocket * const socket = qobject_cast<QUdpSocket *>(sender());
          Q_CHECK_PTR(socket);
          // do stuff with socket.
      }
      

      Cheers.

      yuvaramY 1 Reply Last reply
      3
      • Paul ColbyP Paul Colby

        Hi @yuvaram,

        I want to bind fixed 3 IP addresses only.

        As far as I know, the underlying OS sockets (on Linux, at least) only support one or all interfaces for a single bind. Qt probably doesn't extend on that.

        So I think you would need to have three separate UDP binds, but you can connect them all to the same slot anyway, like:

        MyClass::MyClass() {
            for (const QHostAddress &address, addresses) {
                QUdpSocket * const socket = new QUdpSocket(this);
                connect(socket, SIGNAL(readyRead()), this, SLOT(mySlot()));
                socket->bind(address, 12345);
            }
        }
        
        void MyClass::mySlot() {
            QUdpSocket * const socket = qobject_cast<QUdpSocket *>(sender());
            Q_CHECK_PTR(socket);
            // do stuff with socket.
        }
        

        Cheers.

        yuvaramY Offline
        yuvaramY Offline
        yuvaram
        wrote on last edited by yuvaram
        #3

        @Paul-Colby
        You mean that there it need to create 3 different sockets and bind it.
        thank you.

        Yuvaram Aligeti
        Embedded Qt Developer
        : )

        1 Reply Last reply
        0
        • Paul ColbyP Offline
          Paul ColbyP Offline
          Paul Colby
          wrote on last edited by
          #4

          @yuvaram said:

          You mean that there it need to create 3 different sockets and bind it.

          Yep, you're right - I meant three separate sockets, each bound once :)

          Cheers.

          1 Reply Last reply
          0

          • Login

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