Skip to content
QtWS25 Call for Papers
  • 0 Votes
    4 Posts
    532 Views
    Pablo J. RoginaP

    @AlexisLara19 said in QTcpSocket to PLC S1200:

    but don't works fine

    What are the issues?
    The problem is that you cannot use it with Qt?
    Are you able to use it standalone?

  • 0 Votes
    7 Posts
    2k Views
    O

    @SGaist I tried ffmpeg and vlc sadly with those libraries there were 2 seconds of delay. I want stream to be realtime. Plus my friend needs to access each frame in order to process it. With QT we can do such thing thanks to QByteArray and QBuffer.

  • 0 Votes
    3 Posts
    2k Views
    E

    That just shifts from one bottleneck (RAM) to another bottleneck (HDD) and when client sends gigabytes of data it's a bad idea. And in case server crashes, someone will need to manage those large files and re-sending that data will occupy network again which is wasting resources.
    The best solution is for client to see if server is busy and don't send data and I found workaround how to do that.
    In Qt5.10 sources i can clearly see that QTcpSpcket internal read notifications is disabled (qabstractsocket.cpp; bool QAbstractSocketPrivate::canReadNotification(); line 697) when read buffer is full and to enable read notifications you need to read all buffer to make it empty OR use QAbstractSocket::setReadBufferSize(newSize) which internally enables read notifications WHEN newSize is not 0 (unlimited) and not equal to oldSize (qabstractsocket.cpp; void QAbstractSocket::setReadBufferSize(qint64 size); line 2824). Here's a short function for that:

    QTcpSocket socket; qint64 readBufferSize; // Current max read buffer size. bool flag = false; // flag for changing max read buffer size. bool isReadBufferLimitReached = false; void App::CheckReadBufferLimitReached() { if (readBufferSize <= socket.bytesAvailable()) isReadBufferLimitReached = true; else if (isReadBufferLimitReached) { if (flag) { readBufferSize++; flag = !flag; } else { readBufferSize--; flag = !flag; } socket.setReadBufferSize(readBufferSize); isReadBufferLimitReached = false; } }

    In the function which reads data from QTcpSocket at the set intervals, BEFORE reading data, I call this function, which checks if read buffer is full and sets isReadBufferLimitReached if true. Then I read needed amount of data from QTcpSocket and AT THE END I call that function again, which, if buffer were full before, calls QAbstractSocket::setReadBufferSize(newSize) to set new buffer size and enable internal read notifications. Changing read buffer size by +/-1 should be safe, because you read at least 1 byte from socket.

    And on client side you can use QAbstractSocket::bytesToWrite(), QAbstractSocket::flush() or QAbstractSocket::waitForBytesWritten() to know if server is busy.

  • 0 Votes
    6 Posts
    2k Views
    SGaistS

    There's one other thing that is strange, the documentation of netcat explicitly state that you should not use -p and -l together. So what exactly are you connecting to ?

  • 0 Votes
    9 Posts
    4k Views
    SGaistS

    What default location did you had in mind ?

  • 0 Votes
    8 Posts
    4k Views
    divergerD

    @jsulm Thanks, I'll give it a try.