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. Help using QUdpSocket in blocking mode without an event loop
Forum Updated to NodeBB v4.3 + New Features

Help using QUdpSocket in blocking mode without an event loop

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

    Hi

    Having problems using qudpsocket in blocking mode

    My code is below, runs in a seperate thread

    @
    void run()
    {

    QUdpSocket s;
    s.bind();

    forever
    {

    //get data from other thread

    //code to process data

    //then send out on wire
    qint64 n;
    n = s.writeDatagram( buffer, len, QHostAddress("........."), port);
    s.flush();
    s.waitForBytesWritten(-1);
    
    if (len != n)
              qDebug() << "Error sending data << qPrintable(s.errorString());
    

    }
    }

    @

    The code was originally written using bsd sockets using sendto (socket.h) in blocking mode.

    The writeDatagram function function sometimes fails with QAbstractSocket::NetworkError, however the original sendto never failed

    I suppose the bottom line is how do I make the QUdpSocket writeDatagram function work like socket.h sendto function?

    Thanks

    1 Reply Last reply
    0
    • R Offline
      R Offline
      ryadav
      wrote on last edited by
      #2

      you could try waitForBytesWritten

      "Your text to link here...":http://doc.qt.nokia.com/4.8-snapshot/qabstractsocket.html#waitForBytesWritten

      Kind Regards,
      Rajinder Yadav

      SafetyNet Test Driven Development
      http://safetynet.devmentor.org

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dbrmik
        wrote on last edited by
        #3

        Hi

        Yes, if you look at the code you will see that I have tried that. What I dont understand is a way to make writeDatagram behave like socket.h function sendto in blocking mode.

        Any help would be appreciated

        Regards

        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