Skip to content Skip to sidebar Skip to footer

Sending Data Through Socket Spaces, Receiving With Spaces

I'm using C++ with QT4 for this. And when I try to send large html files(in this case, 8kb), the process of sending and receiving work well. But the file received come with spaces

Solution 1:

@Eugen i suspect the quint16 is either not written at all or is at the end of the file. Read below.

@Patrick don't repost only because you feel like not being served fast enough. Stackowerflow is not a hotline.

The stuff you are getting back in the file is not your original text, but QString serialization form, which is unsuprisingly UTF-16. If you want your text back, read the input QDataStream back to QString and save that into file.

While prefixing your data with a length is generally a good idea, it is absolutely redundant with QString >> QDataStream. Read up something here or here. Moreover you have developed a mind boggingly obfuscated way which i suspect is doing nothing. QByteArray is not implementing QIODevice (indeed, why it should) so your out.device()->seek() is a base virtual implementation, empty and just returning true. I won't be surprised if your length "header" is found at the end of your serialization dump file.

Edit: i think that your html transport might start working correctly only by leaving out the confused quint operation completely and use out QTextStream instead of QByteStream.

Solution 2:

I bet there are not spaces between characters (but 0s) & you get the extra chars due to your use of quint16.

Solution 3:

I solved the problem writing it to a file and getting this file to a QByteArray, and sending the QbyteArray entirely to the socket.

Post a Comment for "Sending Data Through Socket Spaces, Receiving With Spaces"