Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUST

tcp listener rust

use std::net::{TcpListener, TcpStream};

fn handle_client(stream: TcpStream) {
    // ...
}

fn main() -> std::io::Result<()> {
    let listener = TcpListener::bind("127.0.0.1:80")?;

    // accept connections and process them serially
    for stream in listener.incoming() {
        handle_client(stream?);
    }
    Ok(())
}
Source by doc.rust-lang.org #
 
PREVIOUS NEXT
Tagged: #tcp #listener #rust
ADD COMMENT
Topic
Name
5+4 =