The Global ARCHICAD Community

Stay informed. Get help. Share your knowledge.

Discussions about using GRAPHISOFT's tools (API DevKit) for independent software developers

Moderators: Karl Ottenstein, LaszloNagy, ejrolon, Barry Kelly, gkmethy, Tibor Lorántfy, MOREH Tamas, Akos Somorjai, Ed Brown, Mihály Palenik

By vuego
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?

Code: Select all   ClientConnection clientConnection(connectionUrl);
   try {

      Request getRequest(Method::Get, url);

      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);

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

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

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




         return targetFile;


   catch (...) {