# Asynchronous (non-blocking) downloading using TCastleDownload class, and other HTTP communication features

**URL:** https://forum.castle-engine.io/t/asynchronous-non-blocking-downloading-using-tcastledownload-class-and-other-http-communication-features/191
**Category:** News
**Created:** [July 19, 2020, 2:45am UTC](https://forum.castle-engine.io/t/asynchronous-non-blocking-downloading-using-tcastledownload-class-and-other-http-communication-features/191 "2020-07-19T02:45:21Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [July 19, 2020, 2:45am UTC](https://forum.castle-engine.io/t/asynchronous-non-blocking-downloading-using-tcastledownload-class-and-other-http-communication-features/191/1 "2020-07-19T02:45:21Z")

</div>

| [![asynchronous\_download screenshot](upload://2Fl8ZCsl7C9VZjtfjNal4AHGmMK.png)](https://castle-engine.io/wp/wp-content/uploads/2020/07/screenshot-2020-07-19-042727-select.png "asynchronous\_download screenshot") |

The new class [TCastleDownload](https://castle-engine.io/apidoc-unstable/html/CastleDownload.TCastleDownload.html) allows to download data over `http` and `https` asynchronously, without blocking the main thread of the application. This means that you can trivially continue rendering and game logic, while some resource are being downloaded over the network.

I made a demo in [examples/network/asynchronous\_download/](https://github.com/castle-engine/castle-engine/blob/master/examples/network/asynchronous_download/). It demonstrates multiple simultaneous downloads, and underneath a glTF animation is playing with smooth 60 FPS without any breaks.

The class supports all CGE URLs, like `file`, `http`, `https`, `castle-data` and more.  
  
[Manual chapter about networking](https://castle-engine.io/manual_network.php) was updated to reflect all new possibilities.

Features:

- The download can be observed (looking at [Status](https://castle-engine.io/apidoc-unstable/html/CastleDownload.TCastleDownload.html#Status), [DownloadedBytes](https://castle-engine.io/apidoc-unstable/html/CastleDownload.TCastleDownload.html#DownloadedBytes), [TotalBytes](https://castle-engine.io/apidoc-unstable/html/CastleDownload.TCastleDownload.html#TotalBytes)).
- When it’s finished, look at [Contents](https://castle-engine.io/apidoc-unstable/html/CastleDownload.TCastleDownload.html#Contents) (if success) or [ErrorMessage](https://castle-engine.io/apidoc-unstable/html/CastleDownload.TCastleDownload.html#ErrorMessage) (if error, that is `Status = dsError`).

- We can read MIME type from server (can be used throughout our engine to designate file type).

- It’s actually a full-featured HTTP(S) web request. You can specify [HttpMethod](https://castle-engine.io/apidoc-unstable/html/CastleDownload.TCastleDownload.html#HttpMethod), like GET, POST, PUT etc. For POST, you can provide form data as [PostData](https://castle-engine.io/apidoc-unstable/html/CastleDownload.TCastleDownload.html#PostData). Arbitrary HTTP headers can be specified using [AddHeader](https://castle-engine.io/apidoc-unstable/html/CastleDownload.TCastleDownload.html#AddHeader).

More examples:

- [examples/network/castle\_download/](https://github.com/castle-engine/castle-engine/blob/master/examples/network/castle_download/) was reimplemented. It implements a simple command-line downloading tool (like `wget` or `curl` using our engine) using `TCastleDownload`.
- [examples/network/remote\_logging/](https://github.com/castle-engine/castle-engine/blob/master/examples/network/remote_logging/) sends now asynchronous HTTP POST message using new `TCastleDownload`.

_This feature was done thanks to [your support on Patreon](https://www.patreon.com/castleengine). It was requested by Peardox. Many thanks! If you like what I’m doing, please [support our engine](https://www.patreon.com/castleengine)._
