Return a list of files that are included.
This commit is contained in:
14
src/main.rs
14
src/main.rs
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user