Skip to content
Snippets Groups Projects
Commit ef5b1bb3 authored by Robert Hedman's avatar Robert Hedman
Browse files

Somwehat workign tcp messaging

parent d4efdb94
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,12 @@ use std::thread;
use std::sync::mpsc;
use std::time;
// stuff for tcp
use std::io::prelude::*;
use std::net::TcpStream;
use std::net::TcpListener;
use std::str;
// should the map matrix be two dim array of const size, vecs of dynamic, or what?
......@@ -72,7 +78,7 @@ fn main() {
// update map
if pos.0 == 1000000 {
if pos.0 == 2000 {
println!("mapper done.");
request_location_tx.send(false).unwrap();
break;
......@@ -84,9 +90,49 @@ fn main() {
});
let server = thread::spawn(|| {
let listener = TcpListener::bind("127.0.0.1:8080").unwrap();
let mut stream;
let mut message = [0u8; 13];
match listener.accept() {
Ok((socket, addr)) => {
println!("server: new client: {:?}", addr); stream=socket;
thread::sleep(time::Duration::new(1,0));
//loop {
match stream.read(&mut message) {
Ok(msg) => {println!("server got: {:?}, local message: {}", msg, str::from_utf8(&message).unwrap());
//stream.write(String::from("yo").as_bytes()).unwrap();
},
Err(e) => {println!("Some error in readToString in swerver: {}", e)},
}
//}
},
Err(e) => println!("couldn't get client: {:?}", e),
}
});
thread::sleep(time::Duration::new(3,0));
let mut stream = TcpStream::connect("127.0.0.1:8080").unwrap();
//thread::sleep(time::Duration::new(0,900*1000000));
//let written_size = stream.write(&['y' as u8,'o' as u8, '!' as u8]);
//println!("main wrote {:?} bytes to stream.", written_size);
let written_size = stream.write_all("Main says hi.".as_bytes());
println!("main wrote_all {:?} to stream.", written_size);
//let mut message = String::with_capacity(127);
/*match stream.read_to_string(&mut message) {
Ok(m) => {println!("main got: {:?}", m)},
Err(e) => {println!("Main could not read to string: {:?}", e);},
};*/
println!("Main wating for join.");
mapper.join().unwrap();
tracker.join().unwrap();
println!("Main wating for server join.");
//drop(stream);
server.join().unwrap();
println!("end of main");
// pathfinder, takes a map and returns a list of nodes to aim for when driving
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment