I found Chris Wellons’ endlessh to be very neat, so I wrote a short one in Rust. This compiles down to about 337kB after stripping metadata on the current-thread flavor of tokio.

If you want to try it yourself, you can run it with ./binname [PORT NUMBER].

use std::{env, time::Duration};
use tokio::{self, io::AsyncWriteExt, net::TcpListener, time::interval};

#[tokio::main]
async fn main() {
    let port: String = env::args().skip(1).collect();
    let listener = TcpListener::bind(format!("0.0.0.0:{}", port))
        .await
        .expect("failed to bind to port");

    loop {
        if let Ok((mut stream, _)) = listener.accept().await {
            tokio::spawn(async move {
                let mut interval = interval(Duration::from_secs(5));
                loop {
                    if let Err(e) = stream.write(b"\n").await {
                        eprintln!("{}", e);
                    }
                    interval.tick().await;
                }
            });
        }
    }
}