<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic ClientConnection partial download in Archicad C++ API</title>
    <link>https://community.graphisoft.com/t5/Archicad-C-API/ClientConnection-partial-download/m-p/231608#M3945</link>
    <description>&lt;DIV class="actalk-migrated-content"&gt;I am downloading a binary file (gsm object) with ClientConnection class.&lt;BR /&gt;When working in development environment with faster localhost server which serves gsm objects, everything works fine. &lt;BR /&gt;&lt;BR /&gt;When I moved to a production server on different location, with slower internet access, I started getting partial downloads. After using a short sleep() in a loop, it works again but it is a bad solution.&lt;BR /&gt;&lt;BR /&gt;Obviously BeginReceive() function works asynchronously. How can I check/wait if I've received all data?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;	ClientConnection clientConnection(connectionUrl);
	try {
		clientConnection.Connect();

		Request getRequest(Method::Get, url);
		clientConnection.Send(getRequest);

		Response response;
		GS::IChannelX channel(clientConnection.BeginReceive(response), GS::GetNetworkByteOrderIProtocolX());
		GS::GSSize bufLen = 0;

		if (response.GetStatusCode() == 200) {
			IO::File* targetFile = new IO::File(dest, IO::File::Create);
			targetFile-&amp;gt;Open(IO::File::WriteMode);

			while ((bufLen = (GS::GSSize)channel.GetAvailable()) &amp;gt; 0) {

				GSPtr buffer = BMAllocatePtr(bufLen, ALLOCATE_CLEAR, 0);

				channel.ReadBin((char *)buffer, bufLen);
				targetFile-&amp;gt;WriteBin((char *)buffer, bufLen);

				BMKillPtr(&amp;amp;buffer);
				Sleep(100);
			}

			targetFile-&amp;gt;Close();

			clientConnection.FinishReceive();
			clientConnection.Close(false);

			return targetFile;

		}


		clientConnection.FinishReceive();
		clientConnection.Close(false);
	}
	catch (...) {

	}
&lt;/PRE&gt;
&lt;/DIV&gt;</description>
    <pubDate>Wed, 12 Jul 2023 18:51:42 GMT</pubDate>
    <dc:creator>Miha Nahtigal</dc:creator>
    <dc:date>2023-07-12T18:51:42Z</dc:date>
    <item>
      <title>ClientConnection partial download</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/ClientConnection-partial-download/m-p/231608#M3945</link>
      <description>&lt;DIV class="actalk-migrated-content"&gt;I am downloading a binary file (gsm object) with ClientConnection class.&lt;BR /&gt;When working in development environment with faster localhost server which serves gsm objects, everything works fine. &lt;BR /&gt;&lt;BR /&gt;When I moved to a production server on different location, with slower internet access, I started getting partial downloads. After using a short sleep() in a loop, it works again but it is a bad solution.&lt;BR /&gt;&lt;BR /&gt;Obviously BeginReceive() function works asynchronously. How can I check/wait if I've received all data?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;	ClientConnection clientConnection(connectionUrl);
	try {
		clientConnection.Connect();

		Request getRequest(Method::Get, url);
		clientConnection.Send(getRequest);

		Response response;
		GS::IChannelX channel(clientConnection.BeginReceive(response), GS::GetNetworkByteOrderIProtocolX());
		GS::GSSize bufLen = 0;

		if (response.GetStatusCode() == 200) {
			IO::File* targetFile = new IO::File(dest, IO::File::Create);
			targetFile-&amp;gt;Open(IO::File::WriteMode);

			while ((bufLen = (GS::GSSize)channel.GetAvailable()) &amp;gt; 0) {

				GSPtr buffer = BMAllocatePtr(bufLen, ALLOCATE_CLEAR, 0);

				channel.ReadBin((char *)buffer, bufLen);
				targetFile-&amp;gt;WriteBin((char *)buffer, bufLen);

				BMKillPtr(&amp;amp;buffer);
				Sleep(100);
			}

			targetFile-&amp;gt;Close();

			clientConnection.FinishReceive();
			clientConnection.Close(false);

			return targetFile;

		}


		clientConnection.FinishReceive();
		clientConnection.Close(false);
	}
	catch (...) {

	}
&lt;/PRE&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 12 Jul 2023 18:51:42 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/ClientConnection-partial-download/m-p/231608#M3945</guid>
      <dc:creator>Miha Nahtigal</dc:creator>
      <dc:date>2023-07-12T18:51:42Z</dc:date>
    </item>
  </channel>
</rss>

