home page -> teaching -> parallel and distributed programming -> lab 4 - Futures and continuations

Lab 4 - Futures and continuations

Due: week 8

Goal

The goal of this lab is to use C# TPL futures and continuations in a more complex scenario, in conjunction with waiting for external events.

Requirement

Write a program that is capable of simultaneously downloading several files through HTTP. Use directly the BeginConnect()/EndConnect(), BeginSend()/EndSend() and BeginReceive()/EndReceive() Socket functions, and write a simple parser for the HTTP protocol (it should be able only to get the header lines and to understand the Content-lenght: header line).

Try three implementations:

  1. Directly implement the parser on the callbacks (event-driven);
  2. (bonus - 2p) Wrap the connect/send/receive operations in tasks, with the callback setting the result of the task; then chain the tasks with ContinueWith().
  3. Create wrappers like above for connect/send/receive, but then use async/await mechanism.

Note: do not use Wait() calls, except in Main() to wait for all tasks to complete after setting everything up.

Examples

srv-begin-end.cs

srv-tasks-loop.cs

srv-await.cs

A client for the above servers: srv-client.cs

Radu-Lucian LUPŞA
2025-10-05