pub async fn listen_for_tcp_on<S: TcpService, T: tokio::net::ToSocketAddrs + Send + Sync>(
        &self,
        addr: T,
        service: S,
    ) -> Result<(), Error> {
        let listener = TcpListener::bind(&addr).await?;
        let mut shutdown_watcher = self
            .data
            .shutdown
            .watcher()
            .await
            .expect("server already shutdown");

        loop {
            tokio::select! {
                _ = shutdown_watcher.wait_for_shutdown() => {
                    break;
                }
                incoming = listener.accept() => {
                    if incoming.is_err() {
                        continue;
                    }
                    let (connection, remote_addr) = incoming.unwrap();

                    let peer = Peer {
                        address: remote_addr,
                        protocol: service.available_protocols()[0].clone(),
                        secure: false,
                    };

                    let task_self = self.clone();
                    let task_service = service.clone();
                    tokio::spawn(async move {
                        if let Err(err) = task_self.handle_tcp_connection(connection, peer, &task_service).await {
                            log::error!("[server] closing connection {}: {:?}", remote_addr, err);
                        }
                    });
                }
            }
        }

        Ok(())
    }
/// Listens for HTTP traffic on `port`. This port will also receive
/// `WebSocket` connections if feature `websockets` is enabled.
Listens for HTTP traffic on `port`. This port will also receive
`WebSocket` connections if feature `websockets` is enabled.
Listens for HTTP traffic on ` port ` . This port will also receive ` WebSocket ` connections if feature ` websockets ` is enabled .
pub async fn listen_for_tcp_on<S: TcpService, T: tokio::net::ToSocketAddrs + Send + Sync>(
        &self,
        addr: T,
        service: S,
    ) -> Result<(), Error> {
        let listener = TcpListener::bind(&addr).await?;
        let mut shutdown_watcher = self
            .data
            .shutdown
            .watcher()
            .await
            .expect("server already shutdown");
        loop {
            tokio::select! {
                _ = shutdown_watcher.wait_for_shutdown() => {
                    break;
                }
                incoming = listener.accept() => {
                    if incoming.is_err() {
                        continue;
                    }
                    let (connection, remote_addr) = incoming.unwrap();
                    let peer = Peer {
                        address: remote_addr,
                        protocol: service.available_protocols()[0].clone(),
                        secure: false,
                    };
                    let task_self = self.clone();
                    let task_service = service.clone();
                    tokio::spawn(async move {
                        if let Err(err) = task_self.handle_tcp_connection(connection, peer, &task_service).await {
                            log::error!("[server] closing connection {}: {:?}", remote_addr, err);
                        }
                    });
                }
            }
        }
        Ok(())
    }
pub async fn listen_for_tcp_on < S : TcpService , T : tokio :: net :: ToSocketAddrs + Send + Sync > ( & self , addr : T , service : S , ) -> Result < ( ) , Error > { let listener = TcpListener :: bind ( & addr ) . await ? ; let mut shutdown_watcher = self . data . shutdown . watcher ( ) . await . expect ( " " ) ; loop { tokio :: select ! { shutdown_watcher wait_for_shutdown ( ) { break } incoming listener accept ( ) { if incoming is_err ( ) { continue } let ( connection remote_addr ) incoming unwrap ( ) let peer Peer { address remote_addr protocol service available_protocols ( ) [ 0 ] clone ( ) secure false } let task_self self clone ( ) let task_service service clone ( ) tokio spawn ( async move { if let Err ( err ) task_self handle_tcp_connection ( connection peer task_service ) await { log error ( " " remote_addr err ) } } ) } } } Ok ( ( ) ) }
Listens for HTTP traffic on `port`.
Listens for HTTP traffic on ` port ` .
&self
addr
T
service
S
&self
addr
T
service
S