Created
July 3, 2024 14:05
-
-
Save Chaz6/b0a333530016e5c4e79245fcaf039ca1 to your computer and use it in GitHub Desktop.
daytime server in rust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use chrono::Local; | |
use std::io::Write; | |
use std::net::{TcpListener, TcpStream}; | |
fn handle_client(mut stream: TcpStream) { | |
let dt = Local::now().to_utc(); | |
stream.write_all(dt.to_string().as_bytes()).unwrap(); | |
stream.shutdown(std::net::Shutdown::Both).unwrap(); | |
} | |
fn main() -> std::io::Result<()> { | |
let listener = TcpListener::bind("[::]:13")?; | |
for stream in listener.incoming() { | |
handle_client(stream?); | |
} | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment