summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: d6908cb7ddfca4a6747eaeb25fa3713903ec276a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
mod configuration;
mod renderer;
mod screen;
mod telnet;

use configuration::Configuration;
use telnet::handle_client;

use std::io::Result;
use std::net::TcpListener;
use std::thread;

/// Spawns a server and hands over the connection to the telnet client handler.
fn main() -> Result<()> {
    let configuration = Configuration::new();

    let listener = TcpListener::bind(&configuration.address)?;
    eprintln!(
        "Server is now listening on address {}",
        configuration.address
    );

    for stream in listener.incoming() {
        match stream {
            Ok(stream) => {
                thread::spawn(move || {
                    if let Err(error) =
                        handle_client(stream, configuration.frequency, configuration.modulation)
                    {
                        eprintln!("Error handling client: {error}");
                    }
                });
            }
            Err(error) => {
                eprintln!("Connection failed: {error}");
            }
        }
    }

    Ok(())
}