Error correction mechanisms enable control and other real-time applications to be executed over unreliable packet-switched networks. By adding carefully adjusted redundancy to transmitted data at the sender, it is possible to recover lost data at the receiver and thereby improve effective throughput. We describe simple models for packet loss, which allow us to find the optimal redundancy as a function of packet loss probability. Two feedforward control mechanisms based on the packet loss probability are presented: one that is computed off-line and another one using an on-line algorithm. A drawback with these approaches is their dependency on accurate network state information and precise loss models. To cope with these issues, we propose a new feedback solution that tracks the optimum using gradient estimation. Simulations in ns-2 illustrate the behavior of the error correction schemes, demonstrating that the feedback solution outperforms the feedforward solution in presence of model errors.