Do I receive complete QByteArray when binaryMessageReceived is emitted?
-
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 ?
-
@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.
-
@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 thatQWebSocket::binaryMessageReceived()
does receive the whole message. (It may effectively "block", or at least take a while to complete.) There is aQWebSocket::binaryFrameReceived()
which receives it in multiple frames. -
@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.