Open ports on client

This commit is contained in:
2022-08-30 11:16:22 +02:00
parent 09b5403390
commit c67d53a4df
4 changed files with 76 additions and 13 deletions

View File

@@ -1,9 +1,11 @@
use std::future::Future;
use std::net::TcpListener;
use std::time::Duration;
pub fn relay_client(token: &str, port_id: usize, server: &str, listen_address: &str) {
use tokio::net::TcpListener;
pub async fn relay_client(token: String, port_id: usize, server: String, listen_address: String) {
log::info!("({}) Start to listen on {}", port_id, listen_address);
let listener = match TcpListener::bind(&listen_address) {
let listener = match TcpListener::bind(&listen_address).await {
Ok(l) => l,
Err(e) => {
log::error!("Failed to start to listen on {}!", listen_address);
@@ -11,4 +13,14 @@ pub fn relay_client(token: &str, port_id: usize, server: &str, listen_address: &
}
};
loop {
let (mut socket, _) = listener.accept().await
.expect("Failed to accept new connection!");
let token = token.clone();
let listen_address = listen_address.clone();
tokio::spawn(async move {
log::info!("New connection to {}", &listen_address);
});
}
}