diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ee242eb..51de373 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -53,7 +53,9 @@ jobs: - name: Install musl(linux) if: matrix.build == 'linux' - run: sudo apt-get install -y musl-tools + run: + - sudo apt-get install -y musl-tools + - sudo apt-get install -y libssl-dev - name: Build binary run: cargo build --verbose --release --target ${{ matrix.target }} --package airnc diff --git a/.github/workflows/server.yml b/.github/workflows/server.yml index c3206d9..ef722e9 100644 --- a/.github/workflows/server.yml +++ b/.github/workflows/server.yml @@ -24,7 +24,7 @@ jobs: run: sudo apt-get install -y musl-tools - name: Build binary - run: cargo build --verbose --release + run: cargo build --verbose --release --package airnc-server env: RUST_BACKTRACE: 1 diff --git a/crates/cli/src/server.rs b/crates/cli/src/server.rs index 5542831..3ea3f69 100644 --- a/crates/cli/src/server.rs +++ b/crates/cli/src/server.rs @@ -52,11 +52,11 @@ pub async fn run_server(cli: Cli) -> Result<(), std::io::Error> { }; let service_disable = cli.config.service_disable.clone(); - let ws_task = task::spawn(async move { - if !service_disable { + if !service_disable { + task::spawn(async move { connect_and_handle_messages(service).await; - } - }); + }); + } HttpServer::new(move || { App::new() @@ -67,8 +67,6 @@ pub async fn run_server(cli: Cli) -> Result<(), std::io::Error> { .run() .await?; - ws_task.await?; - Ok(()) } diff --git a/crates/cli/src/ws.rs b/crates/cli/src/ws.rs index a72ea56..5d296d8 100644 --- a/crates/cli/src/ws.rs +++ b/crates/cli/src/ws.rs @@ -1,9 +1,5 @@ +use colored::Colorize; use serde::{Deserialize, Serialize}; -use std::process; -use tokio::{ - select, - signal::unix::{signal, SignalKind}, -}; use websockets::{Frame, WebSocket}; #[derive(Deserialize, Serialize, Debug)] @@ -13,37 +9,33 @@ pub struct Service { } pub async fn connect_and_handle_messages(service: Service) { + println!("Ws: server connecting..."); match WebSocket::connect("ws://120.55.189.199:8080/ws").await { Ok(mut ws) => { + println!("{}", "Ws: server connect success".green()); let value = serde_json::to_string(&service).unwrap(); ws.send_text(value).await.unwrap(); - let mut signal = signal(SignalKind::interrupt()).unwrap(); loop { - select! { - _ = signal.recv() => { - process::exit(1); - } - msg = ws.receive() => { + let msg = ws.receive().await; + match msg { + Ok(msg) => { match msg { - Ok(msg) => { - match msg { - Frame::Text { payload, .. } => { - // 处理接收到的文本消息 - println!("➤ Received: {}", payload); - } - Frame::Close { .. } => { - println!("➤ Received close"); - break; - } - _ => {} - } + Frame::Text { payload, .. } => { + // 处理接收到的文本消息 + println!("➤ Received: {}", payload); } - Err(err) => { - println!("websocket connect fail: {}", err); + Frame::Close { .. } => { + println!("➤ Received close"); + break; } + _ => {} } } + Err(err) => { + println!("websocket connect fail: {}", err); + break; + } } } }