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 is read-only?
Forum Updated to NodeBB v4.3 + New Features

QUdpSocket::bind is read-only?

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

    Following scenario:
    there is client and server

    server listens on TCP port for incomming connection

    client connects to this TCP port and sends request

    server responses to the client with list of opened UDP ports

    client connects to the one of UDP port and send request

    server gets request on UDP port and response back

    The problem is: 5. statement isn't done because then I try to response(write) I always get -1 back, and isWritable method of QUdpSocket returns false...
    is UDP socket binds only in read-only mode? So I can't write to it?

    God is Real unless explicitly declared as Integer.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      Did you follow the Broadcast "sender":http://qt-project.org/doc/qt-4.8/network-broadcastsender.html and "receiver":http://qt-project.org/doc/qt-4.8/network-broadcastreceiver.html examples?

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        QtRoS
        wrote on last edited by
        #3

        Can you show some code?
        Using QUdpSocket::bind() only says port and address you will use. So it is possible both to read and write.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          AcerExtensa
          wrote on last edited by
          #4

          Sh*t... I have forgot to make "git add" for new files before commiting... I'll come back and show code next week...
          But bind function looks like that:
          @QUdpSocket * udp_sock = new QUdpSocket(this);
          udp_sock->bind(QHostAddress::Any, 2883, QUdpSocket::DontShareAddress|QUdpSocket::ReuseAddressHint/default for unix*/);@

          So nothing extra ordinary... client can connect to this port(over the internet) and this socket gets incoming data(data is packed with QDataStream with set version), I can read request but can't write an answer... write function always returns -1 and isWritable is false...

          God is Real unless explicitly declared as Integer.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            AcerExtensa
            wrote on last edited by
            #5

            koahnig, I'm doing the same thing if you are talking about that:
            @while (udpSocket->hasPendingDatagrams()) {
            QByteArray datagram;
            datagram.resize(udpSocket->pendingDatagramSize());
            udpSocket->readDatagram(datagram.data(), datagram.size());
            statusLabel->setText(tr("Received datagram: "%1"")
            .arg(datagram.data()));
            }@

            God is Real unless explicitly declared as Integer.

            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