<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Communication via QTcpSocket for data &gt; 8192 bytes]]></title><description><![CDATA[<p dir="auto">Hey there,<br />
I want to exchange a QJsonObject between Server and Client. My code works for not to large data, but when the data is above a size of 8192 Bytes, it doesn't work anymore, although I am sure I take care of multiple packages.<br />
Maybe someone has an idea.<br />
Code as follows:<br />
@<br />
//write<br />
QByteArray p_ByteArray;<br />
QDataStream p_DataSteam(&amp;p_ByteArray, QIODevice::WriteOnly);<br />
p_DataSteam &lt;&lt; (int) -1;<br />
p_ByteArray.append(QJsonDocument(i_JsonObject).toJson());<br />
p_DataSteam.device()-&gt;seek(0);<br />
p_DataSteam &lt;&lt; (int) p_ByteArray.size();</p>
<p dir="auto">int p_Sent = 0;<br />
while(p_Sent&lt;p_ByteArray.size())<br />
{<br />
p_Sent += i_Socket-&gt;write(p_ByteArray.mid(p_Sent,SENT_SIZE));<br />
i_Socket-&gt;waitForBytesWritten(WAIT_TIME);<br />
}</p>
<p dir="auto">if(p_Sent==p_ByteArray.size())<br />
return EXIT_SUCCESS;<br />
else<br />
{<br />
printf("Err: writeSaveJSON failed\n");<br />
return EXIT_FAILURE;<br />
}<br />
@</p>
<p dir="auto">@<br />
//read<br />
QByteArray p_ByteArray;<br />
QDataStream p_DataStream(&amp;p_ByteArray, QIODevice::ReadOnly);<br />
p_ByteArray = i_Socket-&gt;read(sizeof(int));</p>
<p dir="auto">int p_ByteSize;<br />
p_DataStream &gt;&gt; p_ByteSize;</p>
<p dir="auto">while(p_ByteArray.size()&lt;p_ByteSize) // endless loop, since no further data received<br />
{<br />
int p_ToRead = p_ByteSize - (int)p_ByteArray.size();<br />
QByteArray p_ByteArray2 = i_Socket-&gt;read(p_ToRead); // this one is empty after first call<br />
p_ByteArray.append(p_ByteArray2);<br />
//p_ByteArray.append(i_Socket-&gt;read(p_ByteSize-p_ByteArray.size()));<br />
}<br />
if(p_ByteArray.size()!=p_ByteSize)<br />
{<br />
printf("Err: readSaveJSON failed %d %d\n",p_ByteArray.size(),p_ByteSize);<br />
}<br />
p_ByteArray=p_ByteArray.mid(sizeof(int),p_ByteArray.size()-sizeof(int));<br />
return QJsonDocument::fromJson(p_ByteArray).object();<br />
@</p>
<p dir="auto">SENT_SIZE is set to 4096, but that should not matter, I hope.</p>
<p dir="auto">Any ideas?</p>
<p dir="auto">kind regards,<br />
curator</p>
]]></description><link>https://forum.qt.io/topic/47140/communication-via-qtcpsocket-for-data-8192-bytes</link><generator>RSS for Node</generator><lastBuildDate>Wed, 23 Sep 2026 18:03:26 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/47140.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 17 Oct 2014 14:20:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Communication via QTcpSocket for data &gt; 8192 bytes on Mon, 20 Oct 2014 12:39:39 GMT]]></title><description><![CDATA[<p dir="auto">Hi,<br />
The line you mention only ready the size of the array, the main read is in line 12.</p>
<p dir="auto">However, I switched temporary to readAll and it stops after 8192 bytes again</p>
]]></description><link>https://forum.qt.io/post/248327</link><guid isPermaLink="true">https://forum.qt.io/post/248327</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Mon, 20 Oct 2014 12:39:39 GMT</pubDate></item><item><title><![CDATA[Reply to Communication via QTcpSocket for data &gt; 8192 bytes on Mon, 20 Oct 2014 09:34:48 GMT]]></title><description><![CDATA[<p dir="auto">Hi.<br />
From the above you are writing 4096 bytes and reading only 4 bytes.<br />
here<br />
" <em>p_ByteArray = i_Socket-&gt;read(sizeof(int));</em>"<br />
update it by</p>
<ul>
<li>p_ByteArray = i_Socket-&gt;read(4096);*</li>
</ul>
<p dir="auto">if does not work then use readAll().</p>
]]></description><link>https://forum.qt.io/post/248310</link><guid isPermaLink="true">https://forum.qt.io/post/248310</guid><dc:creator><![CDATA[IamSumit]]></dc:creator><pubDate>Mon, 20 Oct 2014 09:34:48 GMT</pubDate></item><item><title><![CDATA[Reply to Communication via QTcpSocket for data &gt; 8192 bytes on Mon, 20 Oct 2014 07:07:44 GMT]]></title><description><![CDATA[<p dir="auto">Hey, thanks for replying.</p>
<p dir="auto">If I get your answer correctly, you say that I send the size of the commited data, where the commited data is extended by the size of the original data. that is correct, but as long as I know that and take care of that in the receiving function, that should not matter?</p>
<p dir="auto">Any further ideas or corrections of this post?</p>
]]></description><link>https://forum.qt.io/post/248281</link><guid isPermaLink="true">https://forum.qt.io/post/248281</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Mon, 20 Oct 2014 07:07:44 GMT</pubDate></item><item><title><![CDATA[Reply to Communication via QTcpSocket for data &gt; 8192 bytes on Fri, 17 Oct 2014 22:53:15 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">@p_DataSteam &lt;&lt; (int) p_ByteArray.size(); &lt;&lt; wrong size@</p>
<p dir="auto">You are giving the size of the complete array, you should only give the payload size</p>
]]></description><link>https://forum.qt.io/post/248046</link><guid isPermaLink="true">https://forum.qt.io/post/248046</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Fri, 17 Oct 2014 22:53:15 GMT</pubDate></item></channel></rss>