Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 10 additions & 35 deletions crates/socketioxide/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,21 @@
//! ## A Tower [`Service`](tower_service::Service) and Hyper [`Service`](hyper::service::Service) for socket.io so it
//! can be used with frameworks supporting tower and hyper services.
//!
//! #### Example with a raw `hyper` standalone service (most of the time it is easier to use a framework like `axum` or `salvo`):
//!
//! ```no_run
//! #### Example with axum :
//! ```rust
//! # use socketioxide::SocketIo;
//! # use std::net::SocketAddr;
//! # use hyper::server::conn::http1;
//! # use tokio::net::TcpListener;
//!
//! #[tokio::main]
//! async fn main() {
//! let (svc, io) = SocketIo::new_svc();
//!
//! // Add io namespaces and events...
//! # use axum::routing::get;
//! // Create a socket.io service
//! let (svc, io) = SocketIo::new_svc();
//!
//! // Spawn raw hyper server
//! let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
//! let listener = TcpListener::bind(addr).await.unwrap();
//! // Add io namespaces and events...
//!
//! // We start a loop to continuously accept incoming connections
//! loop {
//! let (stream, _) = listener.accept().await.unwrap();
//! let app = axum::Router::<()>::new()
//! .route("/", get(|| async { "Hello, World!" }))
//! .route_service("/socket.io", svc);
//!
//! // Use an adapter to access something implementing `tokio::io` traits as if they implement
//! // `hyper::rt` IO traits.
//! let io = hyper_util::rt::TokioIo::new(stream);
//! let svc = svc.clone();
//! // Spawn axum server
//!
//! // Spawn a tokio task to serve multiple connections concurrently
//! tokio::task::spawn(async move {
//! // Finally, we bind the incoming connection to our `hello` service
//! if let Err(err) = http1::Builder::new()
//! .serve_connection(io, svc)
//! .with_upgrades()
//! .await
//! {
//! println!("Error serving connection: {:?}", err);
//! }
//! });
//! }
//! }
//! ```

use engineioxide::service::{EngineIoService, MakeEngineIoService};
Expand Down