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. UDP Socket binding problem
Qt 6.11 is out! See what's new in the release blog

UDP Socket binding problem

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.4k 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.
  • B Offline
    B Offline
    big_buka
    wrote on last edited by
    #1

    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);
    return;
    }
    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->writeBytes("admin\0",5);
    *stream << hash.toHex();
    quint16 port=3075;
    QHostAddress adr("192.168.1.96");
    qint64 sent=_sock->writeDatagram(datagram,adr,3075);
    @

    Problem:
    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

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      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?

      Greetz, Jeroen

      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