feat: retry connect clash.
This commit is contained in:
parent
42d65a559d
commit
9a541e1090
48
src/main.rs
48
src/main.rs
@ -1,8 +1,12 @@
|
|||||||
use std::format;
|
use std::{format, time::Duration};
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use futures_util::{pin_mut, StreamExt};
|
use futures_util::{pin_mut, StreamExt};
|
||||||
use tokio::io::{stdout, AsyncWriteExt};
|
use log::info;
|
||||||
|
use tokio::{
|
||||||
|
io::{stdout, AsyncWriteExt},
|
||||||
|
time::sleep,
|
||||||
|
};
|
||||||
use tokio_tungstenite::connect_async;
|
use tokio_tungstenite::connect_async;
|
||||||
|
|
||||||
mod clash_conn_msg;
|
mod clash_conn_msg;
|
||||||
@ -36,6 +40,14 @@ async fn main() {
|
|||||||
|
|
||||||
let connect_addr = args.clash_url;
|
let connect_addr = args.clash_url;
|
||||||
|
|
||||||
|
loop {
|
||||||
|
pipe(connect_addr.clone()).await;
|
||||||
|
sleep(Duration::from_secs(1)).await;
|
||||||
|
info!("restart!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn pipe(connect_addr: String) {
|
||||||
let url = url::Url::parse(&connect_addr).unwrap();
|
let url = url::Url::parse(&connect_addr).unwrap();
|
||||||
|
|
||||||
let (ws_stream, _) = connect_async(url).await.expect("Failed to connect");
|
let (ws_stream, _) = connect_async(url).await.expect("Failed to connect");
|
||||||
@ -64,22 +76,22 @@ async fn main() {
|
|||||||
|
|
||||||
let state = statistics_manager.get_state().await;
|
let state = statistics_manager.get_state().await;
|
||||||
|
|
||||||
stdout()
|
// stdout()
|
||||||
.write_all(
|
// .write_all(
|
||||||
format!(
|
// format!(
|
||||||
"len: {},speed_upload: {}, speed_download: {}, update_direct_speed: {}, download_direct_speed: {}, update_proxy_speed: {}, download_proxy_speed: {}\n",
|
// "len: {},speed_upload: {}, speed_download: {}, update_direct_speed: {}, download_direct_speed: {}, update_proxy_speed: {}, download_proxy_speed: {}\n",
|
||||||
state.connections,
|
// state.connections,
|
||||||
state.speed_upload,
|
// state.speed_upload,
|
||||||
state.speed_download,
|
// state.speed_download,
|
||||||
state.direct_upload_speed,
|
// state.direct_upload_speed,
|
||||||
state.direct_download_speed,
|
// state.direct_download_speed,
|
||||||
state.proxy_upload_speed,
|
// state.proxy_upload_speed,
|
||||||
state.proxy_download_speed,
|
// state.proxy_download_speed,
|
||||||
)
|
// )
|
||||||
.as_bytes(),
|
// .as_bytes(),
|
||||||
)
|
// )
|
||||||
.await
|
// .await
|
||||||
.unwrap();
|
// .unwrap();
|
||||||
|
|
||||||
let udp_server = udp_server::UdpServer::global().await;
|
let udp_server = udp_server::UdpServer::global().await;
|
||||||
let mut buf = [0; 32];
|
let mut buf = [0; 32];
|
||||||
|
Loading…
Reference in New Issue
Block a user