リモートサーバの構築
リモートサーバを構築することで, AUTDとの通信処理をサーバに委譲することができる.
セットアップ
リモートサーバを走らせるには, Rustをインストールする必要がある.
次に, 以下のコマンドでRustのプロジェクトを新規作成する.
cargo new autd_remote_server
cd autd_remote_server
次にautd3-link-remote crateと非同期ランタイムとしてtokioを追加する.
cargo add autd3-link-remote --features server
cargo add tokio --features full
次に, 適当なLinkを追加する. ここでは説明のため, autd3 crateにあるダミーのNopリンクを使用する.
cargo add autd3 --features link-nop
次に, src/main.rsを以下のように編集する.
RemoteServer::newの第1引数には使用するポート番号を, 第2引数には使用するLinkを指定する.
use autd3_link_remote::RemoteServer;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
RemoteServer::new(8080, autd3::link::Nop::new())
.with_graceful_shutdown(async { tokio::signal::ctrl_c().await.unwrap() })
.run()
.await?;
Ok(())
}
あとは, クライアント側でRemoteリンクを使用して, サーバに接続すれば良い.