add files

This commit is contained in:
Nicholas Orlowsky 2023-08-02 23:14:46 -05:00 committed by Nicholas Orlowsky
commit 206ccb66ad
140 changed files with 367 additions and 0 deletions

View file

@ -0,0 +1,33 @@
use std::net::{TcpStream};
use std::io::{Read, Write};
use std::str::from_utf8;
use std::io;
fn main() {
match TcpStream::connect("localhost:5433") {
Ok(mut stream) => {
println!("Connected to Database");
loop {
print!("SQUIRREL: ");
io::stdout().flush().unwrap();
let mut msg_str = String::new();
std::io::stdin().read_line(&mut msg_str).unwrap();
let msg = msg_str.as_bytes();
stream.write(msg).unwrap();
let mut response_size_buffer = [0 as u8; 8];
stream.read_exact(&mut response_size_buffer).unwrap();
let response_size: usize = usize::from_le_bytes(response_size_buffer);
let mut response_buffer = vec![0 as u8; response_size];
stream.read_exact(&mut response_buffer).unwrap();
println!("{}", String::from_utf8(response_buffer).expect("a utf-8 string"));
}
},
Err(e) => {
println!("Failed to connect: {}", e);
}
}
}