-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(examples): split examples between libraries
- Loading branch information
Showing
13 changed files
with
811 additions
and
241 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "axum-echo" | ||
version = "0.6.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
socketioxide = { path = "../../socketioxide" } | ||
axum = { version = "0.6.20" } | ||
tokio = { version = "1.33.0", features = ["full"] } | ||
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } | ||
tracing = "0.1.37" | ||
serde = "1.0.188" | ||
serde_json = "1.0.107" | ||
futures = "0.3.28" | ||
|
||
[[bin]] | ||
name = "axum-echo" | ||
path = "axum_echo.rs" |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "hyper-echo" | ||
version = "0.6.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
socketioxide = { path = "../../socketioxide" } | ||
hyper = { version = "0.14.27" } | ||
tokio = { version = "1.33.0", features = ["full"] } | ||
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } | ||
tracing = "0.1.37" | ||
serde = "1.0.188" | ||
serde_json = "1.0.107" | ||
futures = "0.3.28" | ||
|
||
[[bin]] | ||
name = "hyper-echo" | ||
path = "hyper_echo.rs" |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "salvo-echo" | ||
version = "0.6.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
engineioxide = { path = "../../engineioxide", feature = ["hyper-v1"] } | ||
salvo = { version = "0.58.2", features = ["tower-compat"] } | ||
tokio = { version = "1.33.0", features = ["full"] } | ||
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } | ||
tracing = "0.1.37" | ||
serde = "1.0.188" | ||
serde_json = "1.0.107" | ||
futures = "0.3.28" | ||
|
||
[[bin]] | ||
name = "salvo-echo" | ||
path = "salvo_echo.rs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use salvo::prelude::*; | ||
use salvo::tower_compat::TowerServiceCompat; | ||
|
||
use std::sync::Arc; | ||
|
||
use engineioxide::{ | ||
handler::EngineIoHandler, | ||
service::EngineIoService, | ||
socket::{DisconnectReason, Socket}, | ||
}; | ||
use tracing::Level; | ||
use tracing_subscriber::FmtSubscriber; | ||
|
||
#[derive(Debug, Clone)] | ||
struct MyHandler; | ||
|
||
#[engineioxide::async_trait] | ||
impl EngineIoHandler for MyHandler { | ||
type Data = (); | ||
|
||
fn on_connect(&self, socket: Arc<Socket<Self::Data>>) { | ||
println!("socket connect {}", socket.id); | ||
} | ||
fn on_disconnect(&self, socket: Arc<Socket<Self::Data>>, reason: DisconnectReason) { | ||
println!("socket disconnect {}: {:?}", socket.id, reason); | ||
} | ||
|
||
fn on_message(&self, msg: String, socket: Arc<Socket<Self::Data>>) { | ||
println!("Ping pong message {:?}", msg); | ||
socket.emit(msg).ok(); | ||
} | ||
|
||
fn on_binary(&self, data: Vec<u8>, socket: Arc<Socket<Self::Data>>) { | ||
println!("Ping pong binary message {:?}", data); | ||
socket.emit_binary(data).ok(); | ||
} | ||
} | ||
|
||
#[handler] | ||
async fn hello() -> &'static str { | ||
"Hello World" | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let subscriber = FmtSubscriber::builder() | ||
.with_line_number(true) | ||
.with_max_level(Level::DEBUG) | ||
.finish(); | ||
tracing::subscriber::set_global_default(subscriber)?; | ||
|
||
let svc = EngineIoService::new(MyHandler).compat(); | ||
|
||
let router = Router::new().get(hello); | ||
let acceptor = TcpListener::new("127.0.0.1:5800").bind().await; | ||
Server::new(acceptor).serve(router).await; | ||
|
||
Ok(()) | ||
} |
19 changes: 4 additions & 15 deletions
19
examples/socketio-echo/Cargo.toml → examples/warp-echo/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,21 @@ | ||
[package] | ||
name = "socketio-echo" | ||
name = "engineio-echo" | ||
version = "0.6.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
socketioxide = { path = "../../socketioxide" } | ||
axum = { version = "0.6.20" } | ||
warp = { version = "0.3.6" } | ||
hyper = { version = "0.14.27" } | ||
tokio = { version = "1.33.0", features = ["full"] } | ||
tower = { version = "0.4.13" } | ||
tower-http = { version = "0.4.4", features = ["cors"] } | ||
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } | ||
tracing = "0.1.37" | ||
serde = "1.0.188" | ||
serde_json = "1.0.107" | ||
futures = "0.3.28" | ||
|
||
[[example]] | ||
name = "socketio-axum-echo" | ||
path = "src/axum_echo.rs" | ||
|
||
[[example]] | ||
name = "socketio-hyper-echo" | ||
path = "src/hyper_echo.rs" | ||
|
||
[[example]] | ||
name = "socketio-warp-echo" | ||
path = "src/warp_echo.rs" | ||
[[bin]] | ||
name = "warp-echo" | ||
path = "warp_echo.rs" |
File renamed without changes.