pub async fn server(config: Config, udp_address: SocketAddr) -> Result<(), tokio::io::Error> {
    let socket = UdpSocket::bind(&config.udp_address).await?;
    info!("UDP Server: ONLINE ON [{}]", config.udp_address);

    info!("UDP Server: Connecting to [{}]", udp_address);
    socket.connect(udp_address).await?;

    println!();

    let mut tasks_num = 0_u8;

    for task in config.get_tasks() {
        info!("[Task manager]: sending task data");

        match task {
            Task::GCD { numbers, result } => {
                for number in numbers {
                    socket.send_to(&packet(number), &udp_address).await?;
                }

                let data = recv(&socket).await?;
                if data == format!("{}", result) {
                    info!("[Task GCD]: completed!");
                } else {
                    error!("[Task GCD]: failed! Provided: [{}], Expected: [{}]", data, result);
                    break;
                }
            }
            Task::SUM { numbers, result } => {
                for number in numbers {
                    socket.send_to(&packet(number), &udp_address).await?;
                }

                let data = recv(&socket).await?;
                if data == format!("{}", result) {
                    info!("[Task SUM]: completed!");
                } else {
                    error!("[Task SUM]: failed! Provided: [{}], Expected: [{}]", data, result);
                    break;
                }
            }
            Task::XK { x, result, .. } => {
                socket.send_to(&packet(x), &udp_address).await?;

                let data = recv(&socket).await?;
                if data == format!("{}", result) {
                    info!("[Task XK]: completed!");
                } else {
                    error!("[Task XK]: failed! Provided: [{}], Expected: [{}]", data, result);
                    break;
                }
            }
            Task::StringDeletion { target, result, .. } => {
                socket.send_to(&packet(target), &udp_address).await?;

                let data = recv(&socket).await?;
                if data == format!("{}", result) {
                    info!("[Task SD]: completed!");
                } else {
                    error!("[Task SD]: failed! Provided: [{}], Expected: [{}]", data, result);
                    break;
                }
            }
            Task::StringConcat { target, result } => {
                socket.send_to(&packet(target), &udp_address).await?;

                let data = recv(&socket).await?;
                if data == format!("{}", result) {
                    info!("[Task SC]: completed!");
                } else {
                    error!("[Task SC]: failed! Provided: [{}], Expected: [{}]", data, result);
                    break;
                }
            }
        }

        tasks_num += 1;
    }

    if tasks_num >= crate::TASKS_AMOUNT {
        socket.send_to(&packet(config.final_flag), &udp_address).await?;
    }

    Ok(())
}
/// Creates a UDP server simulating SKJ's UDP server behaviour
///
/// # Arguments
/// * `config` - A Config structure
/// * `udp_address` - UDP client's address received from previous TCP connection
///
Creates a UDP server simulating SKJ's UDP server behaviour
Creates a UDP server simulating SKJ ' s UDP server behaviour
pub async fn server(config: Config, udp_address: SocketAddr) -> Result<(), tokio::io::Error> {
    let socket = UdpSocket::bind(&config.udp_address).await?;
    info!("UDP Server: ONLINE ON [{}]", config.udp_address);
    info!("UDP Server: Connecting to [{}]", udp_address);
    socket.connect(udp_address).await?;
    println!();
    let mut tasks_num = 0_u8;
    for task in config.get_tasks() {
        info!("[Task manager]: sending task data");
        match task {
            Task::GCD { numbers, result } => {
                for number in numbers {
                    socket.send_to(&packet(number), &udp_address).await?;
                }
                let data = recv(&socket).await?;
                if data == format!("{}", result) {
                    info!("[Task GCD]: completed!");
                } else {
                    error!("[Task GCD]: failed! Provided: [{}], Expected: [{}]", data, result);
                    break;
                }
            }
            Task::SUM { numbers, result } => {
                for number in numbers {
                    socket.send_to(&packet(number), &udp_address).await?;
                }
                let data = recv(&socket).await?;
                if data == format!("{}", result) {
                    info!("[Task SUM]: completed!");
                } else {
                    error!("[Task SUM]: failed! Provided: [{}], Expected: [{}]", data, result);
                    break;
                }
            }
            Task::XK { x, result, .. } => {
                socket.send_to(&packet(x), &udp_address).await?;
                let data = recv(&socket).await?;
                if data == format!("{}", result) {
                    info!("[Task XK]: completed!");
                } else {
                    error!("[Task XK]: failed! Provided: [{}], Expected: [{}]", data, result);
                    break;
                }
            }
            Task::StringDeletion { target, result, .. } => {
                socket.send_to(&packet(target), &udp_address).await?;
                let data = recv(&socket).await?;
                if data == format!("{}", result) {
                    info!("[Task SD]: completed!");
                } else {
                    error!("[Task SD]: failed! Provided: [{}], Expected: [{}]", data, result);
                    break;
                }
            }
            Task::StringConcat { target, result } => {
                socket.send_to(&packet(target), &udp_address).await?;
                let data = recv(&socket).await?;
                if data == format!("{}", result) {
                    info!("[Task SC]: completed!");
                } else {
                    error!("[Task SC]: failed! Provided: [{}], Expected: [{}]", data, result);
                    break;
                }
            }
        }
        tasks_num += 1;
    }
    if tasks_num >= crate::TASKS_AMOUNT {
        socket.send_to(&packet(config.final_flag), &udp_address).await?;
    }
    Ok(())
}
pub async fn server ( config : Config , udp_address : SocketAddr ) -> Result < ( ) , tokio :: io :: Error > { let socket = UdpSocket :: bind ( & config . udp_address ) . await ? ; info ! ( " " config udp_address ) ; info ! ( " " udp_address ) ; socket . connect ( udp_address ) . await ? ; println ! ( ) ; let mut tasks_num = 0_u8 ; for task in config . get_tasks ( ) { info ! ( " " ) ; match task { Task :: GCD { numbers , result } => { for number in numbers { socket . send_to ( & packet ( number ) , & udp_address ) . await ? ; } let data = recv ( & socket ) . await ? ; if data == format ! ( " " result ) { info ! ( " " ) ; } else { error ! ( " " data result ) ; break ; } } Task :: SUM { numbers , result } => { for number in numbers { socket . send_to ( & packet ( number ) , & udp_address ) . await ? ; } let data = recv ( & socket ) . await ? ; if data == format ! ( " " result ) { info ! ( " " ) ; } else { error ! ( " " data result ) ; break ; } } Task :: XK { x , result , .. } => { socket . send_to ( & packet ( x ) , & udp_address ) . await ? ; let data = recv ( & socket ) . await ? ; if data == format ! ( " " result ) { info ! ( " " ) ; } else { error ! ( " " data result ) ; break ; } } Task :: StringDeletion { target , result , .. } => { socket . send_to ( & packet ( target ) , & udp_address ) . await ? ; let data = recv ( & socket ) . await ? ; if data == format ! ( " " result ) { info ! ( " " ) ; } else { error ! ( " " data result ) ; break ; } } Task :: StringConcat { target , result } => { socket . send_to ( & packet ( target ) , & udp_address ) . await ? ; let data = recv ( & socket ) . await ? ; if data == format ! ( " " result ) { info ! ( " " ) ; } else { error ! ( " " data result ) ; break ; } } } tasks_num += 1 ; } if tasks_num >= crate :: TASKS_AMOUNT { socket . send_to ( & packet ( config . final_flag ) , & udp_address ) . await ? ; } Ok ( ( ) ) }
Creates a UDP server simulating SKJ's UDP server behaviour
Creates a UDP server simulating SKJ ' s UDP server behaviour
config
Config
udp_address
SocketAddr