Hello folk !

I've got a trouble I don't understand : the bind on the QUdpSocket doesn't
conplains but I don't receive anything if I put my IP Address in
_bindAddress. So the binding on AnyIPv4 works but not for adresses.

(the soft I'm working on is multi OS (Linux/Windows) I develop and test on
Linux and I can answer your questions as fast as possible, and even try
your suggestions).

Here is my code simplified (I've got log for each failed line, but what
ever) :

    QUdpSocket* socket = new QUdpSocket(this);


    // Use a regular expression to parse the adress

    QRegularExpression re( "^(\\d+.\\d+.\\d+.\\d+):(\\d+)$");

    QRegularExpressionMatch match = re.match(address);

    if ( !match.hasMatch() )

    {

        qb::warn( QString("Invalid address %1").arg(address) );

        return 0;

    }


    // Get the bind address

    QHostAddress bindAddr( _bindAddress );

        if ( _bindAddress.isEmpty() )

        {

                qb::inform("Use default bind address");

                bindAddr = QHostAddress::AnyIPv4;

        }

        else

        {

                qb::inform("Bind address: " + bindAddr.toString());

        }


    // Bind to the port

    int port = match.captured(2).toInt();

    if (!socket->bind( bindAddr , port, QAbstractSocket::ShareAddress
| QAbstractSocket::ReuseAddressHint ))

    {

        qb::warn( QString("Not possible to bind to %1:%2 :
%3").arg(_bindAddress).arg(port).arg(socket->errorString()) );

        return 0;

    }

        else

        {

                qb::inform( QString("Local address: %1, Peer address: %2, Peer 
port:
%3, Peer name: 
%4.").arg(socket->localAddress().toString()).arg(socket->peerAddress().toString()).arg(socket->peerPort()).arg(socket->peerName())
);

        }


    // Join the multicast group

    QString ipAddress = match.captured(1);

    if (!socket->joinMulticastGroup( QHostAddress(ipAddress) ))

    {

        qb::warn( QString("Cannot join %1 :
%2").arg(ipAddress).arg(socket->errorString()) );

        return 0;

    }


    // IMPORTANT : set the maximum receive buffer size

    // Allow to reach high throughput (4Mb/s) without too many lost packets

    // Default value does not seem to be good enough

    setsockopt(socket->socketDescriptor(), SOL_SOCKET, SO_RCVBUF,
(const char*) &_socketBufferSize, sizeof(int));



    qb::inform( QString("Start listening to %1:%2").arg(ipAddress).arg(port) );


    connect(socket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));

    connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this,
SLOT(onSocketError(QAbstractSocket::SocketError)));





Many thanks in advance

-- 
Jean-Nicolas
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to