Initial MeshPort SDK and cross-platform client

This commit is contained in:
shenlei
2026-10-10 15:16:32 +09:00
commit e73e599165
664 changed files with 209894 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
use meshport::Network;
use std::{net::SocketAddr, time::Duration};
use tokio::io::{AsyncReadExt, AsyncWriteExt};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let args: Vec<_> = std::env::args().collect();
anyhow::ensure!(
args.len() == 3,
"usage: tcp_client <config.toml> <virtual-ip:port>"
);
let config = std::fs::read_to_string(&args[1])?;
let target: SocketAddr = args[2].parse()?;
let network = Network::start(&config).await?;
let result = async {
let mut stream = network.connect_tcp(target, Duration::from_secs(10)).await?;
stream.write_all(b"MeshPort TCP example").await?;
let mut buffer = [0; 256];
let n = tokio::time::timeout(Duration::from_secs(5), stream.read(&mut buffer)).await??;
println!("Received {n} bytes: {:?}", &buffer[..n]);
Ok::<_, anyhow::Error>(())
}
.await;
network.stop().await;
result
}