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. QtCreator and boost::asio::ip::udp::socket vs QUdpSocket

QtCreator and boost::asio::ip::udp::socket vs QUdpSocket

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 3.2k 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.
  • M Offline
    M Offline
    Milosz
    wrote on last edited by
    #1

    Hi everybody,

    I am writting a program with QtCreator which is intended to receive UDP data
    from the source sending about 20 MBps (on the local machine for the time being).
    At the begininig of my project I used QUdpSocket object but I realized
    that it was to slow and can NOT keep up to receive so many data.
    Some online forums I was confirmed that it is true - QUdpSocket is slow
    and I was advised to use boost::asio::ip::udp::socket. I connected it to QtCreator
    and wrote code on the tutorial
    http://www.boost.org/doc/libs/1_35_0/doc/html/boost_asio/tutorial/tutdaytime6.html basis.
    Hovever I have some problems.
    The structure of Qt project is not adequate to the code from the tutorial.

    My code:

    @int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    oscilloscope::Oscilloscope w;
    w.show();

    return a.exec();
    

    }
    @

    oscilloscope.h:
    @class Oscilloscope
    {
    ...
    boost::asio::io_service io_serv;
    UdpReceiver *port1;
    ...
    }
    @

    oscilloscope.cpp

    @oscilloscope::oscilloscope()
    {
    ...........
    try
    {
    port1 = new UdpReceiver(io_serv);
    io_serv.run(); // <- it is very important
    }
    catch(std::exception& e)
    {
    std::cerr << e.what() << "\n";
    }
    ...........
    }
    @

    udpreceiver.h

    @class UdpReceiver
    {
    udp::socket sockPort;
    udp::endpoint remote_endpoint;
    boost::array<char, 1> rec_buffer;

    public:
    UdpReceiver(boost::asio::io_service & io_serv);

    private:
    void StartReceive();
    void handle_receive(const boost::system::error_code& error,
    std::size_t bytes_transferred);
    };
    @

    udpreceiver.cpp

    @UdpReceiver::UdpReceiver(boost::asio::io_service & io_serv):
    sockPort(io_serv, udp::endpoint(udp::v4(), 7755))
    {
    StartReceive();
    }

    void UdpReceiver::StartReceive()
    {
    sockPort.async_receive_from(
    boost::asio::buffer(rec_buffer), remote_endpoint,
    boost::bind(&UdpReceiver::handle_receive, this,
    boost::asio::placeholders::error,
    boost::asio::placeholders::bytes_transferred));

    }

    void UdpReceiver::handle_receive(const boost::system::error_code& error,
    std::size_t bytes_transferred)
    {
    if (!error || error == boost::asio::error::message_size)
    {
    std::string err = error.message();
    StartReceive();
    }
    else
    {
    std::string ss = error.message();
    std::cerr << ss << " " << error.value() << "\n";

    StartReceive();
    }
    }
    @

    Application enter to function handle_receive properly when receiving data
    but the first condition is always FALSE.
    The second condition (else) is performed and prints
    error 234 - More data is available.

    What does it mean? Where did I make an error?
    Could someone help me?
    Is it true that QUdpSocket is such slow?

    Thanks for your help in advance.
    Best regards.
    Milosz

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ckakman
      wrote on last edited by
      #2

      Hi,

      Your question seems to be about boost not Qt. Maybe you should ask your question on a boost forum/mailing list.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Milosz
        wrote on last edited by
        #3

        ckakman, you are right but I asked among others very important question concerning Qt. The question was: "Is it true that QUdpSocket is such slow?".

        Could anyone answer me?
        Best regards

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          [quote author="Milosz" date="1421653198"]Is it true that QUdpSocket is such slow?[/quote]Try it :) Write two different programs, where one uses QUdpSocket and the other uses boost::asio::ip::udp::socket. See if you notice any difference.

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          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