You are here: Start » Program Examples » IO HTTP Image Download

IO HTTP Image Download

Aim

The task is to download an image from www.adaptive-vision.com using TCP IP connection.

Input

A hostname of website to connect to.

Output

The downloaded image messe.jpg and information about it.

Hints

To download the messe.jpg image from www.adaptive-vision.com you need to send the following query string through connected TCP socket: GET /site_media/native/content/messe.jpg HTTP/1.0. The task can be easily solved using filters from the TCP IP category and LoadImageFromBuffer filter.

Solution (AVS)

  1. Add TcpIp_Connect filter to connects as a client to server socket.
  2. Add TcpIp_WriteText filter to send query string and header through a connected TCP socket.
    • Connect its input inSocket with output of TcpIp_Connect filter.
    • Set inText to: GET /site_media/native/content/messe.jpg HTTP/1.0 Host: www.adaptive-vision.com Accept: image/* Connection: close.
    • Set inSuffix to \r\n\r\n.
  3. Add TcpIp_ReadLine filter to read response headers and connect it with output of TcpIp_Connect filter.
  4. Add TcpIp_ReadAllBuffer to receive data from a connected socket. Set inTimeout to 2000.
  5. To convert received data from a ByteBuffer type to an Image type add LoadImageFromBuffer filter and connect its input inBuffer to output of TcpIp_ReadAllBuffer filter.
  6. To close socket add TcpIp_Close filter.

Macrofilter Main

Used Filters

Icon Name Description
TcpIp_Close Close a connected TCP socket gracefully.
TcpIp_Connect Connects as a client to a remote TCP server socket.
TcpIp_ReadAllBuffer Receives data from a connected socket until the other side closes connection.
TcpIp_WriteText Outputs a string through a connected TCP socket.
TcpIp_ReadLine Reads from a connected TCP socket until receiving a specific sequence.
LoadImageFromBuffer Use this filter when you received an image file through I/O communication, e.g. through a TcpIp connection.

Further Readings