Return a list of files that are included.

This commit is contained in:
2025-11-28 17:28:41 +00:00
parent ba60ab41cc
commit dfd6c9c370
4 changed files with 434 additions and 16 deletions

View File

@@ -1,6 +1,6 @@
use std::io;
use std::
{
io,
io::{BufReader, prelude::*},
net::{TcpListener, TcpStream},
};
@@ -10,23 +10,25 @@ mod files;
fn main() -> io::Result<()>
{
let bind_address: &str = "127.0.0.1:2025";
let index_file: &str = "index.npon";
let listener = TcpListener::bind(bind_address).unwrap();
println!("Listening at {}", bind_address);
let mut file_list: Vec<String> = vec![index_file.to_string()];
let (bytes, mut new_file_list) = files::read_file(index_file, 0);
file_list.append(&mut new_file_list);
println!("Files encoded: {:?}", file_list);
for stream in listener.incoming() {
let stream = stream.unwrap();
handle_connection(stream);
handle_connection(stream, &bytes);
}
Ok(())
}
fn handle_connection(mut stream: TcpStream)
fn handle_connection(mut stream: TcpStream, bytes: &Vec<u8>)
{
let buf_reader = BufReader::new(&stream);
println!("CONNECTION: {buf_reader:#?}");
let bytes = files::read_file("index.npon", 0);
stream.write_all(bytes.as_slice()).unwrap();
}