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. Do I receive complete QByteArray when binaryMessageReceived is emitted?
QtWS25 Last Chance

Do I receive complete QByteArray when binaryMessageReceived is emitted?

Scheduled Pinned Locked Moved Solved General and Desktop
qwebsocketnetworkingtcpqbytearray
4 Posts 3 Posters 743 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.
  • nooneN Offline
    nooneN Offline
    noone
    wrote on last edited by
    #1

    I am currnly using QTcpServer on server side with few Worker threads. both Client and server communicatw with eath other with QTcpSocket. If I am correct then when large (in my case ~10MB) QByteArray is sent, client receives it in chunks and emits multiple readReady signal and we can get received bytes number with bytesAvailable function.

    This is getting hard to manage for me with my own custom protocol so I thought QWebSocket might be more easier to use So I wanted to switch to QWebSocket

    I dont see any bytesAvailable function in QWebSocket. So does this mean when I call

    QWebSocket::sendBinaryMessage( MyQByteArrayObj)
    

    the signal

    QWebSocket::binaryMessageReceived(MyQByteArrayObj)
    

    emitted on client on client side contains same and complete MyQByteArrayObj as on Server side ?

    JonBJ 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #3

      @noone said in Do I receive complete QByteArray when binaryMessageReceived is emitted?:

      same and complete MyQByteArrayObj as on Server side ?

      Yes, that's what QWebSocket is for - always get the complete message and don't care for the underlying stream. But I would not recommend to send 100MB at once.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • nooneN noone

        I am currnly using QTcpServer on server side with few Worker threads. both Client and server communicatw with eath other with QTcpSocket. If I am correct then when large (in my case ~10MB) QByteArray is sent, client receives it in chunks and emits multiple readReady signal and we can get received bytes number with bytesAvailable function.

        This is getting hard to manage for me with my own custom protocol so I thought QWebSocket might be more easier to use So I wanted to switch to QWebSocket

        I dont see any bytesAvailable function in QWebSocket. So does this mean when I call

        QWebSocket::sendBinaryMessage( MyQByteArrayObj)
        

        the signal

        QWebSocket::binaryMessageReceived(MyQByteArrayObj)
        

        emitted on client on client side contains same and complete MyQByteArrayObj as on Server side ?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #2

        @noone
        I don't know why your custom protocol cannot handle the data arriving in chunks, it should be able to. You could have used https://doc.qt.io/qt-5/qdatastream.html#startTransaction to help you, e.g. https://forum.qt.io/topic/74769/how-to-use-qdatatstream-starttransaction-properly-with-qtcpsocket.

        I haven't used QWebSocket, but it seems apparent to me that QWebSocket::binaryMessageReceived() does receive the whole message. (It may effectively "block", or at least take a while to complete.) There is a QWebSocket::binaryFrameReceived() which receives it in multiple frames.

        nooneN 1 Reply Last reply
        1
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #3

          @noone said in Do I receive complete QByteArray when binaryMessageReceived is emitted?:

          same and complete MyQByteArrayObj as on Server side ?

          Yes, that's what QWebSocket is for - always get the complete message and don't care for the underlying stream. But I would not recommend to send 100MB at once.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          3
          • JonBJ JonB

            @noone
            I don't know why your custom protocol cannot handle the data arriving in chunks, it should be able to. You could have used https://doc.qt.io/qt-5/qdatastream.html#startTransaction to help you, e.g. https://forum.qt.io/topic/74769/how-to-use-qdatatstream-starttransaction-properly-with-qtcpsocket.

            I haven't used QWebSocket, but it seems apparent to me that QWebSocket::binaryMessageReceived() does receive the whole message. (It may effectively "block", or at least take a while to complete.) There is a QWebSocket::binaryFrameReceived() which receives it in multiple frames.

            nooneN Offline
            nooneN Offline
            noone
            wrote on last edited by
            #4

            @JonB Thanks. I didn't know about those links. they look promising. This whole networking stuff is really new to me

            @Christian-Ehrlicher Thanks. So for large data, I guess QWebSocket::binaryFrameReceived() is the correct way

            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