|
|
|
@ -5,11 +5,10 @@ use std::io::{BufReader, Result}; |
|
|
|
mod protocol; |
|
|
|
|
|
|
|
|
|
|
|
fn handle_connection(stream: TcpStream) -> Result<()> { |
|
|
|
fn handle_connection(stream: TcpStream, prot: &mut protocol::Protocol) -> Result<()> { |
|
|
|
let mut outstream = stream.try_clone()?; |
|
|
|
let mut reader = BufReader::new(stream); |
|
|
|
let mut text = String::new(); |
|
|
|
let mut prot = protocol::Protocol::new(); |
|
|
|
|
|
|
|
prot.start(); |
|
|
|
write!(outstream,"Hello to 7seg-writer!\n").expect("could not write to TCP Stream!"); |
|
|
|
@ -36,20 +35,25 @@ fn handle_connection(stream: TcpStream) -> Result<()> { |
|
|
|
|
|
|
|
fn main() -> Result<()> { |
|
|
|
let address = "0.0.0.0:8000"; |
|
|
|
println!("Initialize network"); |
|
|
|
let listener = TcpListener::bind(address).expect("could not start server"); |
|
|
|
|
|
|
|
let mut prot = protocol::Protocol::new(); |
|
|
|
println!("Initialize GPIO"); |
|
|
|
prot.init(); |
|
|
|
println!("Ready"); |
|
|
|
// accept connections and get a TcpStream
|
|
|
|
for connection in listener.incoming() { |
|
|
|
match connection { |
|
|
|
Ok(stream) => { |
|
|
|
//stream.set_nonblocking(false);
|
|
|
|
if let Err(e) = handle_connection(stream) { |
|
|
|
if let Err(e) = handle_connection(stream, &mut prot) { |
|
|
|
println!("error {}", e); |
|
|
|
} |
|
|
|
} |
|
|
|
Err(e) => { println!("connection failed {}\n", e); } |
|
|
|
} |
|
|
|
} |
|
|
|
println!("Shutting down"); |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
|
|
|
|
|