From 264b496ef2138534fa7d44a1b1f64b0f550e9845 Mon Sep 17 00:00:00 2001 From: Nickiel12 <35903114+Nickiel12@users.noreply.github.com> Date: Fri, 17 Dec 2021 12:39:11 -0800 Subject: [PATCH] created basic tcp listener --- src/main.rs | 12 +++++++++++- src/tests/main_tests.rs | 8 ++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 5af09ac..2beb8b1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,16 @@ mod tests; mod modules; +use std::net::{TcpListener, TcpStream, Shutdown}; + fn main() { - println!("Hello, world!"); + let listener = make_listener(String::from("localhost:5000")); + + + + drop(listener); +} + +fn make_listener(address: String) -> TcpListener { + TcpListener::bind(address).unwrap() } diff --git a/src/tests/main_tests.rs b/src/tests/main_tests.rs index da13ea1..53e8ebb 100644 --- a/src/tests/main_tests.rs +++ b/src/tests/main_tests.rs @@ -1,6 +1,14 @@ +use crate::make_listener; + #[test] fn it_works() { let result = 2 + 2; assert_eq!(result, 4); } + +#[test] +fn can_make_socket_listener(){ + let listener = make_listener(String::from("localhost:5000")); + drop(listener); +} \ No newline at end of file