License Delivery maintenance is expected to occur on Saturday, November 30, between 8 AM and 11 AM CET. This may cause a short 3-hours outage in which license-related tasks: license key upload, download, update, SSA validation, access to the license pool and Graphisoft ID authentication may not function properly. We apologize for any inconvenience.
Archicad C++ API
About Archicad add-on development using the C++ API.

ClientConnection partial download

Miha Nahtigal
Advocate
I am downloading a binary file (gsm object) with ClientConnection class.
When working in development environment with faster localhost server which serves gsm objects, everything works fine.

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.

Obviously BeginReceive() function works asynchronously. How can I check/wait if I've received all data?



	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->Open(IO::File::WriteMode);

			while ((bufLen = (GS::GSSize)channel.GetAvailable()) > 0) {

				GSPtr buffer = BMAllocatePtr(bufLen, ALLOCATE_CLEAR, 0);

				channel.ReadBin((char *)buffer, bufLen);
				targetFile->WriteBin((char *)buffer, bufLen);

				BMKillPtr(&buffer);
				Sleep(100);
			}

			targetFile->Close();

			clientConnection.FinishReceive();
			clientConnection.Close(false);

			return targetFile;

		}


		clientConnection.FinishReceive();
		clientConnection.Close(false);
	}
	catch (...) {

	}
BIMquants.comBETA - Quantities and Costs Estimation in Archicad - BETA testers needed.
0 REPLIES 0

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!