PDA

View Full Version : Sending large base64 string over qtcpsocket



jwz104
13th April 2016, 21:00
I want to send files over my qtcpsocket. It also needs to read some text. I am right now using base64. Small files work fine but large file are send in 2 parts for some reason. My read function only reads the first part so only about half of the image is visible when I get it. Does anyone knows a good way to send large files over my qtcpsocket? I still have to read some text because sending files is not the only function. I am receiving the string with the readReady signal en I get it with socket->readAll();

Lesiok
14th April 2016, 07:01
This is normal behaviour - You live with it :)

anda_skoa
14th April 2016, 08:31
A TCP connection is conceptually a byte stream, that gets chopped into packets by the network stack, transmitted to the peer and then reassembled.
The data blocks that arrive can be different sized chunks than what the sender wrote into the socket.

E.g. if a sender writes individual bytes, the receiver might still receive them in mulitbyte blocks.
Or like in your case, writen large blocks can end up being received as a number of smaller blocks.

You will need a protocol that either lets you know beforehand how many bytes belong to one "object" or a way to detect the end of data of one "object".

Cheers,
_