Skip to content

Instantly share code, notes, and snippets.

@Chaz6
Created July 3, 2024 14:05
Show Gist options
  • Save Chaz6/b0a333530016e5c4e79245fcaf039ca1 to your computer and use it in GitHub Desktop.
Save Chaz6/b0a333530016e5c4e79245fcaf039ca1 to your computer and use it in GitHub Desktop.
daytime server in rust
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