ClientConnection partial download
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2017-09-22
08:33 AM
- last edited on
2023-07-12
08:51 PM
by
Doreena Deng
2017-09-22
08:33 AM
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?
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.
Labels:
- Labels:
-
Add-On (C++)
0 REPLIES 0