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
+8
View File
@@ -0,0 +1,8 @@
[package]
name = "meshport-test-server"
version.workspace = true
edition.workspace = true
[dependencies]
tokio.workspace = true
anyhow.workspace = true
+44
View File
@@ -0,0 +1,44 @@
//! Run on the game server; TCP/UDP echo is separate from the actual game service.
use anyhow::Result;
use tokio::{
io::{AsyncReadExt, AsyncWriteExt},
net::{TcpListener, UdpSocket},
};
#[tokio::main]
async fn main() -> Result<()> {
let addr = std::env::args()
.nth(1)
.unwrap_or_else(|| "127.0.0.1:7007".into());
let tcp = TcpListener::bind(&addr).await?;
let udp = UdpSocket::bind(&addr).await?;
println!("MeshPort TCP/UDP echo listening on {addr}");
let tcp_task = async {
loop {
let (mut socket, _) = tcp.accept().await?;
tokio::spawn(async move {
let mut buffer = [0; 16384];
loop {
let n = socket.read(&mut buffer).await?;
if n == 0 {
break;
}
socket.write_all(&buffer[..n]).await?;
}
Ok::<_, std::io::Error>(())
});
}
#[allow(unreachable_code)]
Ok::<(), std::io::Error>(())
};
let udp_task = async {
let mut buffer = [0; 65535];
loop {
let (n, peer) = udp.recv_from(&mut buffer).await?;
udp.send_to(&buffer[..n], peer).await?;
}
#[allow(unreachable_code)]
Ok::<(), std::io::Error>(())
};
tokio::try_join!(tcp_task, udp_task)?;
Ok(())
}