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 writeDatagram fail. Error: "QAbstractSocket::NetworkError"
Forum Updated to NodeBB v4.3 + New Features

QUdpSocket writeDatagram fail. Error: "QAbstractSocket::NetworkError"

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.7k Views
  • 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
    Alexey2016
    wrote on last edited by Alexey2016
    #1

    I need send big data in short time, but have a problem with QUdpSocket.
    Simple test:

    #include <QUdpSocket>
    
    void Test_Fail_QUdpSocket(int packet_size)
    {
        qDebug() << "Start test, packet_size: " << QString::number(packet_size);
        QUdpSocket socket;
        socket.setSocketOption(QAbstractSocket::SendBufferSizeSocketOption, 10*1024*1024); // is not helped
        qint64 sended_all = 0;
        while(1)
        {
            QByteArray bytes(packet_size, 0xcc);
            //QUdpSocket socket; //if uncomment it - working, but too slow 
            qint64 sended = socket.writeDatagram(bytes, QHostAddress("123.123.123.123"), 50000);
            if( sended<0 )
            {
                qDebug() <<"Err: " << QString::number(socket.error()) << "\tSended: " << QString::number(sended_all);
                //I get error with any "sended_all":  7 - QAbstractSocket::NetworkError
                return;
            }
            socket.flush(); // is not helped
            sended_all += packet_size;
        }
    }
    
    int main(int argc, char *argv[])
    {
        Test_Fail_QUdpSocket(256);
    }
    

    If QHostAddress("127.0.0.1") - then all good with any packet_size <= 8192.
    But if host addres is any real host in local network (1Gb) I get error with any packet_size (128,256,512,1024,2048,4096,8192)
    and all targets(x86, x64).

    But if I use Windows sockets(Winsock2.h) and function "send_to()" then all good!

    My: QT 5.5.1, MinGW_492_32, MSVC2013_32, MSVC2013_64.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      you forgot to bind to the port, socket.bind(50000);

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      A 1 Reply Last reply
      0
      • VRoninV VRonin

        you forgot to bind to the port, socket.bind(50000);

        A Offline
        A Offline
        Alexey2016
        wrote on last edited by Alexey2016
        #3

        @VRonin said in QUdpSocket writeDatagram fail. Error: "QAbstractSocket::NetworkError":

        you forgot to bind to the port, socket.bind(50000);

        Binds UDP is needed if want to receive.

        I think so problem in component, becase it is sends packets long without error if I choose a small package size (<512).
        With windows sockets no such problem.

        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