QUdpSocket::bind is read-only?



  • 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?


  • Moderators



  • 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.



  • Sht... 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...



  • 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()));
    }@


Log in to reply
 

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