Important: Please read the Qt Code of Conduct -

UDP Socket binding problem

  • Hello!
    I'm exploring udp sockets in qt and have a little problem...
    Creating a socket:
    _sock = new QUdpSocket(this);

    if (!_sock->bind(QHostAddress::Any, _port))
    Log::Error("LoginServer","Failed to bind %d",_port);
    connect(_sock, SIGNAL(readyRead()), this, SLOT(HandleLogin()));
    Log::Trace("LoginServer","LoginServer successfully binded to %d port",_port);

    connecting to socket
    QString str("abc");
    QByteArray hash = QCryptographicHash::hash(str.toUtf8(), QCryptographicHash::Md5);
    QByteArray datagram;
    QDataStream* stream = new QDataStream(&datagram,QIODevice::WriteOnly);
    *stream << hash.toHex();
    quint16 port=3075;
    QHostAddress adr("");
    qint64 sent=_sock->writeDatagram(datagram,adr,3075);

    if i put instead adr QHostAddress::LocalHost everything is ok connection performed
    but if i put external ip or internal local ip connection don't occured
    port forvarding on my router is set up
    sory for my bad english

  • If the localhost does work it is the connection between the nodes themselves. Maybe try a IP sniffer program to analyse the data on the port your using?

Log in to reply