Tcp Create Listener

    0

    0

    use std::{error::Error, net::SocketAddr};
    
    use tokio::net::TcpListener;
    
    /// Create a listener on a port
    ///
    /// # Arguments
    ///
    /// * `port` - The port to bind to
    ///
    /// # Returns
    ///
    /// * Result<TcpListener, Box<dyn Error>> - The listener
    
    pub async fn create_listener(addr: SocketAddr) -> Result<TcpListener, Box<dyn Error>> {
      let listener = TcpListener::bind(addr).await;
    
      match listener {
        Ok(listener) => Ok(listener),
        Err(e) => Err(e.into()),
      }
    }
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.