13 releases

0.6.2 Jan 30, 2024
0.6.1 Nov 16, 2023
0.6.0 Oct 24, 2023
0.5.1 Mar 17, 2023
0.1.0 Mar 23, 2022

#41 in WebSocket

Download history 94/week @ 2024-01-03 118/week @ 2024-01-10 85/week @ 2024-01-17 105/week @ 2024-01-24 70/week @ 2024-01-31 50/week @ 2024-02-07 92/week @ 2024-02-14 193/week @ 2024-02-21 173/week @ 2024-02-28 101/week @ 2024-03-06 228/week @ 2024-03-13 208/week @ 2024-03-20 233/week @ 2024-03-27 242/week @ 2024-04-03 107/week @ 2024-04-10 105/week @ 2024-04-17

734 downloads per month
Used in 6 crates (3 directly)

MIT license

125KB
2.5K SLoC

ezsockets

Creating a WebSocket server or a client in Rust can be troublesome. This crate facilitates this process by providing:

  • Traits to allow declarative and event-based programming.
  • Easy concurrency with Tokio and async/await. Server sessions are Clone'able and can be shared between tasks.
  • Heartbeat mechanism to keep the connection alive.
  • Automatic reconnection of WebSocket Clients.
  • Support for arbitrary client back-ends, with built-in native and WASM client connectors.
  • Support for multiple server back-ends such as Axum or Tungstenite.
  • TLS support for servers with rustls and native-tls.

Documentation

View the full documentation at docs.rs/ezsockets

Examples

  • simple-client - a simplest WebSocket client which uses stdin as input.
  • echo-server - server that echoes back every message it receives.
  • echo-server - same as echo-server, but with native-tls.
  • counter-server - server that increments global value every second and shares it with client
  • chat-client - chat client for chat-server and chat-server-axum examples
  • wasm-client - chat client for chat-server and chat-server-axum examples that runs in the browser (only listens to the chat)
  • chat-server - chat server with support of rooms
  • chat-server-axum - same as above, but using axum as a back-end

Client

By default clients use tokio-tungstenite under the hood. Disable default features and enable wasm_client to run clients on WASM targets.

See examples/simple-client for a simple usage and docs.rs/ezsockets/server for documentation.

Server

WebSocket server can use one of the supported back-ends:

  • tokio-tungstenite - the simplest way to get started.
  • axum - ergonomic and modular web framework built with Tokio, Tower, and Hyper
  • actix-web - Work in progress at #22

See examples/echo-server for a simple usage and docs.rs/ezsockets/server for documentation.

License

Licensed under MIT.

Contact

Reach me out on Discord gbaranski#5119, or mail me at me@gbaranski.com.

Dependencies

~5–21MB
~320K SLoC