generated from tipragot/rust
Simplify the relay server code #41
|
@ -12,27 +12,9 @@ categories = ["network-programming", "game-development"]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tokio = { version = "1.36.0", features = [
|
tokio = { version = "1.36.0", features = ["macros", "rt-multi-thread"] }
|
||||||
"macros",
|
axum = { version = "0.7.4", features = ["ws"] }
|
||||||
"rt-multi-thread",
|
lazy_static = "1.4.0"
|
||||||
], optional = true }
|
futures = "0.3.30"
|
||||||
axum = { version = "0.7.4", features = ["ws"], optional = true }
|
dashmap = "5.5.3"
|
||||||
lazy_static = { version = "1.4.0", optional = true }
|
rand = "0.8.5"
|
||||||
futures = { version = "0.3.30", optional = true }
|
|
||||||
dashmap = { version = "5.5.3", optional = true }
|
|
||||||
rand = { version = "0.8.5", optional = true }
|
|
||||||
|
|
||||||
[features]
|
|
||||||
default = []
|
|
||||||
server = [
|
|
||||||
"dep:tokio",
|
|
||||||
"dep:axum",
|
|
||||||
"dep:lazy_static",
|
|
||||||
"dep:futures",
|
|
||||||
"dep:dashmap",
|
|
||||||
"dep:rand",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "server"
|
|
||||||
required-features = ["server"]
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ use lazy_static::lazy_static;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use tokio::sync::mpsc::{channel, Receiver, Sender};
|
use tokio::sync::mpsc::{channel, Receiver, Sender};
|
||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref CLIENTS: DashMap<u32, Sender<Vec<u8>>> = DashMap::new();
|
static ref CLIENTS: DashMap<u32, Sender<Vec<u8>>> = DashMap::new();
|
||||||
|
@ -19,7 +18,7 @@ lazy_static! {
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let app = Router::new().route(
|
let app = Router::new().route(
|
||||||
"/relay",
|
"/",
|
||||||
get(|ws: WebSocketUpgrade| async { ws.on_upgrade(handle) }),
|
get(|ws: WebSocketUpgrade| async { ws.on_upgrade(handle) }),
|
||||||
);
|
);
|
||||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:80")
|
let listener = tokio::net::TcpListener::bind("0.0.0.0:80")
|
Loading…
Reference in a new issue