Open ports on client
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user